帮帮看看该C程序是否可以运行

来源:百度知道 编辑:UC知道 时间:2024/05/20 02:47:05
#include <stdio.h>
void fun (char *str)
{int word=0,num=0,letter=0;
while (*str!='\0')
{if (str==" ")
{word=0;
printf("\n");
}
else
letter++ ;
printf("%c",str);
if (word==0)
{word=1;
num++;
}
str++;
}
printf("words %d",&num);
printf("letter %d",&letter);
return
}

void main
{char a[80];
char *string;
scanf("%c",&a);
string=a;
void fun (*string);
}

我只把你的语法错误改了,可以运行的,但我不知道你的程序是干什么用的所以没改你的算法
#include <stdio.h>
void fun (char *str)
{
int word=0,num=0,letter=0;
while (*str!='\0')
{if (str==" ")
{word=0;
printf("\n");
}
else
letter++ ;
printf("%c",str);
if (word==0)
{word=1;
num++;
}
str++;
}
printf("words %d",&num);
printf("letter %d",&letter);
}

void main()
{
char a[80];
char *string;
scanf("%s",&a);
string=a;
fun (string);
}

看了头快大了,不知道你干嘛用的程序
粗略的看一下,指出几处错误,没有去仔细看有没有逻辑的的错误
1: if (str==" ") 对于字符船的比较不能直接用逻辑测试,要用函数
if ((strcmp(str, " ") == 0)
strcmp(str1, str2);strcmp从头开始逐个比较str1个str2中字符,如果str1于str2字符串内容相同则返回0,如果str1中个某个字符ASCII值大于同一位置上str2中的字符,则返回值大于0,否则小于0
2: scanf("%c",&a);字符数组a本身代表字符数组的首地址,不需要再次