- 相關(guān)推薦
如何交換兩個(gè)文本內(nèi)容的C語言代碼
文本存儲的位置:
jack.txt位于: e:jack.txt
retchie.txt位于: e:retchie.txt
內(nèi)容:
jack.txt -> "Hello! I am Jack."
retchie.txt -> "Hello! I am Retchie."
相關(guān)代碼 代碼如下:
#include
int main(void)
{
char temp1[100];
char temp2[100];
FILE *p_jack;
FILE *p_retchie;
p_jack = fopen("e:/jack.txt", "r");
p_retchie = fopen("e:/retchie.txt", "r");
if (p_jack != NULL && p_retchie != NULL)
{
fgets(temp1, 20, p_jack);
fgets(temp2, 20, p_retchie);
}
fclose(p_jack);
fclose(p_retchie);
p_jack = fopen("e:/jack.txt", "w");
p_retchie = fopen("e:/retchie.txt", "w");
if (p_jack != NULL && p_retchie != NULL)
{
fprintf(p_jack, "%s", temp2);
fprintf(p_retchie, "%s", temp1);
fclose(p_jack);
fclose(p_retchie);
}
return 0;
}
運(yùn)行結(jié)果:
內(nèi)容:
jack.txt -> "Hello! I am Retchie."
retchie.txt -> "Hello! I am Jack."
【如何交換兩個(gè)文本內(nèi)容的C語言代碼】相關(guān)文章:
如何提高單片機(jī)C語言代碼效率12-03
C語言快速排序?qū)嵗a06-04
10個(gè)經(jīng)典的C語言面試基礎(chǔ)算法及代碼12-05
C語言插入排序算法及實(shí)例代碼12-05
C語言選擇排序算法及實(shí)例代碼11-25
C語言循環(huán)基礎(chǔ)知識附代碼示例04-12
C語言以數(shù)據(jù)塊的形式讀寫文件實(shí)例代碼12-04
c語言空間換時(shí)間優(yōu)化代碼的技巧方法06-19
如何理解C語言指針03-27