How to check if a file has content or not using C?
问题 I have a source file file1 and a destination file file2 , here I have to move content from file1 to file2 . So I have to do some validation first. I must check source file is existing or not? I can check using this: fp = fopen( argv[1],"r" ); if ( fp == NULL ) { printf( "Could not open source file\n" ); exit(1); } Then I have to check if the source file has any content or not? If it is empty, I have to throw some error message. This is what I've tried until the moment. 回答1: C version: if