august 发表于 2007-4-24 16:36:57

求字符个数问题

程序如下:

#include"stdio.h"
main()
{
    void strle(char *p);
    char array;
    gets(array);

    strle(array);
}
void strle(char *p)
{
    int i=0;
    char *p1;
    for(p1=p;p1!='\0';p1++)
    i++;
    printf("the answer is %d\n",i);
}


为什么这样做错呢,请问应该怎么写才正确呢?

ultranet 发表于 2007-4-24 17:43:14

#include<stdio.h>

void main()
{
void strle(char *p);
char array;
gets(array);
strle(array);
}
void strle(char *p)
{
int i=0;
char *p1=p;
for(*p1=*p;*p1!='\\0';*p1++)
   i++;
printf("the answer is %d\\n",i);
}

Zelsazgh 发表于 2007-5-2 00:18:04

#include"stdio.h"
main()
{
void strle(char *p);
char array;
gets(array);

strle(array);
}
void strle(char *p)
{
int i=0;
char *p1;
for(p1=p;*p1!='\\0';p1++)
    i++;
printf("the answer is %d\\n",i);
}

楼上有部分写错了......
页: [1]
查看完整版本: 求字符个数问题