
如何用c读取多行的.txt文件中的字符串并做判断是否是有想要的字符串
#include #include int main( void ) { FILE* file; char cin; if( ( file = fopen( d:\\\\\\\\1.txt, r ) ) == NULL ) { printf( error can not read 1.txt.\\\ ); getchar(); return 1; } while( !feof(file) ) { cin = fgetc( file );if(cin=='\\\ '){printf(no!\\\ );break; }if( cin == 'y' ) {printf(yes!\\\ );break;} fclose( file ); return 0; } }其中,d:\\\\\\\\3.txt为你的1.txt路径。
已编译通过
如何用C语言实现读取一个字符串的后几位
\\\/\\\/已经在WIN-TC上验 #include int main(){ char *strcut(char *,int); char str[]=abcdefg; printf(%s,strcut(str,3)); getch();}char *strcut(char str[],int m){ int p=0; while(str[p++]) \\\/\\\/计算字符串STR的长度。
{ } p-=1; if(m
=0) \\\/\\\/m的值合法。
return &str[p-m]; else return &str[p];}
用c语言如何从文件用中判断其中字符串为日期,并读取日期前面的字符
这个ch不是用来记录读取的字符是什么的,而是用来判断读取的字符的个数用的,至于为什么while里面是赋值语句,这个和for大概一样的用法,写在括号里的语句会在每次循环时都执行一次