麻烦谁帮我解释下 C语言程序 关于文件查找特殊字符串

麻烦谁帮我解释下 C语言程序 关于文件查找特殊字符串,第1张

#include

<stdio.h>

#include

<stdlib.h>

#include

<string.h>

//三个头文件大吵,分别表示标准化io,标准化库文件,字符串类文件的头文件

int

main()

{

int

line=0//记录行数

FILE

*fp//定义文件指针

char

FILENAME[100],li[256],indata[255],*sust=NULL//

printf("Input

file

name

please:")

gets(FILENAME)//获取文件名

if

((fp=fopen(FILENAME,"r"))!=NULL){//如果读取成功,即fopen函数返回值不为空

printf("Input

a

string

please:")

gets(indata)//袭仿渣输入要寻找的那个字符串

while

(!feof(fp))//当文件未结束一直执行该 *** 作

{

line++//行计数加一

fgets(li,255,fp)//读取255个字符

sust=strstr(li,indata)//从字符串li中寻找indata第一次出现的位置(不比较结束符NULL)。参看//http://baike.baidu.com/view/745156.htm?fr=ala0

if

(sust!=NULL)

{//如果未找到

printf("Found

it

in

line

%d\n",line)

}

}

fclose(fp)//关闭文件

}

else

puts("File

not

found!")//文件未找拍悄到

return

0

}

while((c=getchar())!='?') 意思就是当输入的字符不是“问号”即“?”时喊丛改 执行循环

putchar(--c)意思就是输出c所对应的郑或ASC码的前一个所对应的字符

另外你输入Y?N?<ENTER>。。。Y后面的应该都是多余的吧 getchar()只能读一个字符吧

所以只读进一个Y 因为Y不郑判等于? 所以输出Y的前一个字符就是X

#include <stdio.h>

int brace, brack, paren

void in_quote( int c)

void in_conmment(void)

void search ( int c)

void in_comment ( void )

void main()

{

int c

extern int brace, brace, paren

while( ( c = getchar( ) ) != EOF )

{

if ( ( c = getchar( ) ) == ' * ' )

in_comment ( )

else

search( c )

}

if ( c == ' \ ' || c ==' " ' )

in_quote( c )

else

search ( c )

if ( brace <0 )

{

printf( " Unbalanced braces \n ")

brace = 0

} else if ( brack <0 )

{

printf( " Unbalanced brackets \改空激n ")

brack = 0

} else if ( paren <0 )

{

printf( " Unbalanced parentheses \n ")

paren = 0

}

if ( brace >0 )

printf( " Unbalanced braces \n ")

if ( brack >0 )

printf( " Unbalanced brackets \n ")

if ( paren >0 )

{

printf( " Unbalanced parentheses \n ")

}

}

void search ( int c )

{

extern int brace , brack, paren

if ( c == ' { ' )

++brace

else if ( c == ' } ' )

- - brace

else if ( c == ' [ ' )

++ brack

else if ( c == ' ] ' )

- - brack

else if ( c == ' ( ' )

++paren

else if ( c == ' ) ' )

- -paren

}

void in_comment ( void )

{

int c , d

c = getchar ( )

d= getchar ( )

while ( c != ' * ' || d != ' / ' ) {

c = d

d = getchar ( )

}

}

void in_quote ( int c )

{

int d

while ( ( d = getchar ( ) ) != c )

if ( d == ' \ \核袜 ' )

getchar ( )

}

程序是调试出来了,但不知道是什么意思,错误就是有些分号,中亏戚括号,大括号,格式不正确,应该注意输入法切换,还有一些语法错误。


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/yw/12373654.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-05-23
下一篇2023-05-23

发表评论

登录后才能评论

评论列表(0条)

    保存