C语言文件读写问题(初级学者勿进)

来源:百度知道 编辑:UC知道 时间:2024/05/26 13:41:17
大家看我做的程序,语法是没有问题,就是运行结果有点小问题:
#include<string.h>
#include<stdio.h>
#include<dos.h>
process(char stra[256],char *pa)
{
char strb[40],*strc;
int i=0;
strc=strb;
for(;i<19&&*pa!='.';i++)
{
strb[i]=*pa;
*pa++;
printf("%4d",i);
printf("%c",strb[i]);
}
strb[++i]='\0';
sleep(2);
printf("\n");
printf("strb is %s!\n",strb);
printf("strc is %s!\n",strc);
if(strc=="svchost")printf("find\n");
else printf("not find\n");
}

main()
{
FILE *pf;
char str1[256],str2[40],*p1;
system("cmd /c tasklist >c:\\tasklist.per");
sleep(1);
pf=fopen("c:\\tasklist.per","r");
fgets(str1,256,pf);
fgets(str1,256,pf);
fgets(str1,256,pf);
fgets(str1

if(strc=="svchost")应该改为
if(strcmp(strc,"svchost")==0)或者是
if(!strcmp(strc,"svchost"))

这个问题很简单~!
但是又很难办~!
加我QQ我告诉你~!
这里说不清~!

if(strc=="svchost")
这句几乎是永远不可能相等。可能是这里的问题。

还初级学者未进!!!!!!
在学C语言的哪个不是初级的!!!!!!

这简单的语言早就忘了!!!!!!!!!

C语言 垃圾语言

我认为阁下process函数中这个语句有问题:strb[++i]='\0';
建议改成这样:strb[i]='\0';
这样就不会在结尾多一个字符了.