- 相關推薦
如何交換兩個文本內容的C語言代碼
文本存儲的位置:
jack.txt位于: e:jack.txt
retchie.txt位于: e:retchie.txt
內容:
jack.txt -> "Hello! I am Jack."
retchie.txt -> "Hello! I am Retchie."
相關代碼 代碼如下:
#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;
}
運行結果:
內容:
jack.txt -> "Hello! I am Retchie."
retchie.txt -> "Hello! I am Jack."
【如何交換兩個文本內容的C語言代碼】相關文章:
如何優化C代碼09-23
C語言精簡代碼10-03
如何提高單片機C語言代碼效率10-30
C語言的預處理代碼10-22
C語言快速排序實例代碼10-30
C語言快速排序算法及代碼06-25
C語言合并排序及實例代碼10-30
C語言兎子產子代碼07-30