C語言 逆序顯示文字內容並儲存

2021-07-11 20:16:45 字數 1065 閱讀 4684

【說明】

對指定檔案中的內容或傳入的字串引數逆序列印並儲存到檔案中。

【命令列示例】

[root@localhost]$ ./reversestr test.txt

這條命令的含義是讀取 ./test.txt 檔案中的內容,將檔案內容順序反向儲存到 output.txt 檔案中。

[root@localhost]$ ./reversestr "hello world"

這條命令的含義是將 "hello world" 逆序列印到控制台,並儲存到檔案 output.txt 檔案中。

【原始碼】

#include #include #include int main(char argc, char **argv)

else

printf("%ld bytes been read.\n", ulcountword);

pstrcontent = (char *)malloc((size_t)ulcountword);

fseek(pfileread, 0, seek_set);

printf("%d items been read.\n", fread(pstrcontent, sizeof(char), (size_t)ulcountword, pfileread));

pstrreverse = pstrcontent;

printf("content: %s\n", pstrreverse);

pstrreverse += ulcountword - 1;

if(null == (pfileoutput = fopen("output.txt", "w")))else

fprintf(pfileoutput, "%c", *pstrreverse);

fclose(pfileoutput);

}free(pstrcontent);

fclose(pfileread);

}}else

printf("%c\n", *pstrreverse);

}}else

return 0;

}

C語言 複製檔案內容並儲存

讀取檔案內容並寫入另乙個檔案。file copy.c author 羽墨志 since 2019年8月5日18 13 27 description 檔案複製 include function main author 羽墨志 since 2019年8月5日18 15 41 description 檔案...

C語言向檔案寫入內容並讀取顯示

將學生資訊 姓名 年齡 學號和平均分 寫入檔案,然後讀取顯示出來。要求 實現 複製 純文字複製 include include include define file path d demo.txt 檔案路徑 intmain 從控制台輸入學生資訊並寫入檔案 printf 請輸入姓名 年齡 學號和平均...

C 讀取並顯示word文件中的內容

我想將通道模型的介紹以及分析的情況,都在c 的程式設計中進行實現。然後就想到了將word文件直接顯示到窗體中,並且有滾動條可以拉動進行檢視。蒐集了一些資料之後找到了合適的方法 利用richtextbox開啟乙個有文字格式和的word文件。1.新增引用 要加入word文件,就需要在 解決方案資源管理器...