[已解决]是因为string 的问题吗?(c语言中) 大家帮忙看看。
-
- 帖子: 26
- 注册时间: 2009-04-06 9:36
[已解决]是因为string 的问题吗?(c语言中) 大家帮忙看看。
#include <stdio.h>
#include <stdlib.h>
/*
*
*/
string PriScore( int score[]);
int GetScore(int score[]);
int main(int argc, char** argv)
{
int m;
int scorearray[m];
m = 100;
GetScore(scorearray);
PriScore(scorearray);
return (EXIT_SUCCESS);
}
int GetScore(int score[])
{
int n,value;
while(1)
{
scanf("%d ",&value);
score[n] = value;
if( value == 101) break;
n++;
}
return n;
}
string PriScore(int score[])
{
int i, j, k;
int count[11];
string scores[]={
"0-9 |", "10-19 |", "20-29 |", "30-39 |", "40-49 |",
"50-59 |", "60-69 |", "70-79 |", "80-89 |", "90-99 |",
"100 |",};
for(i = 0; i<= 10; i++)
{
if(score/10 == i)
{
count++;
}
}
for(j = 0; j <= 10; j++)
{
if(count[j] == 0)
{
printf("%s\n ",scores[j]);
} else
{
printf("%s ",scores[j]);
for(k = 0; k < count[j]; k++)
{
printf("*");
}
printf("\n");
}
}
return(EXIT_SUCCESS);
}
运行结果 提示: (上面 下划线和红色的行就是:18 30 48 行)
styloliticchart.c:18: 错误: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘PriScore’
styloliticchart.c: 在函数‘main’中:
styloliticchart.c:30: 警告: 隐式声明函数‘PriScore’
styloliticchart.c: 在文件层:
styloliticchart.c:48: 错误: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘PriScore’
#include <stdlib.h>
/*
*
*/
string PriScore( int score[]);
int GetScore(int score[]);
int main(int argc, char** argv)
{
int m;
int scorearray[m];
m = 100;
GetScore(scorearray);
PriScore(scorearray);
return (EXIT_SUCCESS);
}
int GetScore(int score[])
{
int n,value;
while(1)
{
scanf("%d ",&value);
score[n] = value;
if( value == 101) break;
n++;
}
return n;
}
string PriScore(int score[])
{
int i, j, k;
int count[11];
string scores[]={
"0-9 |", "10-19 |", "20-29 |", "30-39 |", "40-49 |",
"50-59 |", "60-69 |", "70-79 |", "80-89 |", "90-99 |",
"100 |",};
for(i = 0; i<= 10; i++)
{
if(score/10 == i)
{
count++;
}
}
for(j = 0; j <= 10; j++)
{
if(count[j] == 0)
{
printf("%s\n ",scores[j]);
} else
{
printf("%s ",scores[j]);
for(k = 0; k < count[j]; k++)
{
printf("*");
}
printf("\n");
}
}
return(EXIT_SUCCESS);
}
运行结果 提示: (上面 下划线和红色的行就是:18 30 48 行)
styloliticchart.c:18: 错误: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘PriScore’
styloliticchart.c: 在函数‘main’中:
styloliticchart.c:30: 警告: 隐式声明函数‘PriScore’
styloliticchart.c: 在文件层:
styloliticchart.c:48: 错误: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘PriScore’
上次由 ubujie 在 2009-05-09 20:28,总共编辑 1 次。
- libralibra
- 帖子: 401
- 注册时间: 2008-02-23 17:31
- 联系:
Re: 是因为string 的问题吗?(c语言中) 大家帮忙看看。
c里面string是个char数组
能这样写string ***();吗?
能这样写string ***();吗?
-
- 帖子: 26
- 注册时间: 2009-04-06 9:36
Re: 是因为string 的问题吗?(c语言中) 大家帮忙看看。
libralibra 写了:c里面string是个char数组
能这样写string ***();吗?
那改成 char ? 那也不对
-
- 帖子: 26
- 注册时间: 2009-04-06 9:36
Re: 是因为string 的问题吗?(c语言中) 大家帮忙看看。
#include <stdio.h>
#include <stdlib.h>
string scores[11]={
"0-9 |", "10-19 |", "20-29 |", "30-39 |", "40-49 |",
"50-59 |", "60-69 |", "70-79 |", "80-89 |", "90-99 |",
"100 |",};
int main(int argc, char** argv)
{
int i;
string scores[11];
for(i = 0; i <= 10; i++)
{
printf("%s",scores);
}
return 0;
}
为什么 这个都运行不了??
project1test.c:12: 错误: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘scores’
project1test.c: 在函数‘main’中:
project1test.c:20: 错误: ‘string’未声明(在此函数内第一次使用)
project1test.c:20: 错误: (即使在一个函数内多次出现,每个未声明的标识符在其
project1test.c:20: 错误: 所在的函数内也只报告一次。)
project1test.c:20: 错误: expected ‘;’ before ‘scores’
project1test.c:24: 错误: ‘scores’未声明(在此函数内第一次使用)
#include <stdlib.h>
string scores[11]={
"0-9 |", "10-19 |", "20-29 |", "30-39 |", "40-49 |",
"50-59 |", "60-69 |", "70-79 |", "80-89 |", "90-99 |",
"100 |",};
int main(int argc, char** argv)
{
int i;
string scores[11];
for(i = 0; i <= 10; i++)
{
printf("%s",scores);
}
return 0;
}
为什么 这个都运行不了??
project1test.c:12: 错误: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘scores’
project1test.c: 在函数‘main’中:
project1test.c:20: 错误: ‘string’未声明(在此函数内第一次使用)
project1test.c:20: 错误: (即使在一个函数内多次出现,每个未声明的标识符在其
project1test.c:20: 错误: 所在的函数内也只报告一次。)
project1test.c:20: 错误: expected ‘;’ before ‘scores’
project1test.c:24: 错误: ‘scores’未声明(在此函数内第一次使用)
- BigSnake.NET
- 帖子: 12522
- 注册时间: 2006-07-02 11:16
- 来自: 廣州
- 联系:
Re: 是因为string 的问题吗?(c语言中) 大家帮忙看看。
string 未定义
^_^ ~~~
要理解递归,首先要理解递归。
地球人都知道,理论上,理论跟实际是没有差别的,但实际上,理论跟实际的差别是相当大滴。
要理解递归,首先要理解递归。
地球人都知道,理论上,理论跟实际是没有差别的,但实际上,理论跟实际的差别是相当大滴。
-
- 帖子: 26
- 注册时间: 2009-04-06 9:36
Re: 是因为string 的问题吗?(c语言中) 大家帮忙看看。
我知道 string 未定义,但是 string 还要定以吗? 他不是一种 类型吗?BigSnake.NET 写了:string 未定义
如果 要定义 能告我 怎么 定义吗?
- BigSnake.NET
- 帖子: 12522
- 注册时间: 2006-07-02 11:16
- 来自: 廣州
- 联系:
Re: 是因为string 的问题吗?(c语言中) 大家帮忙看看。
显然不是, C 里面没有 string 类型ubujie 写了:我知道 string 未定义,但是 string 还要定以吗? 他不是一种 类型吗?BigSnake.NET 写了:string 未定义
如果 要定义 能告我 怎么 定义吗?
C 用字符数组表示字符串
^_^ ~~~
要理解递归,首先要理解递归。
地球人都知道,理论上,理论跟实际是没有差别的,但实际上,理论跟实际的差别是相当大滴。
要理解递归,首先要理解递归。
地球人都知道,理论上,理论跟实际是没有差别的,但实际上,理论跟实际的差别是相当大滴。
-
- 帖子: 26
- 注册时间: 2009-04-06 9:36
Re: 是因为string 的问题吗?(c语言中) 大家帮忙看看。
先谢谢 大蛇了。
既然这样我就现 找个 接口用呗。
刚学c 语言 不久,还需要 努力!!
既然这样我就现 找个 接口用呗。
刚学c 语言 不久,还需要 努力!!
- libralibra
- 帖子: 401
- 注册时间: 2008-02-23 17:31
- 联系:
Re: 是因为string 的问题吗?(c语言中) 大家帮忙看看。
c中数组都是指针表示的ubujie 写了:libralibra 写了:c里面string是个char数组
能这样写string ***();吗?
那改成 char ? 那也不对
直接char替换不行
定义要char* score[] =...
-
- 帖子: 26
- 注册时间: 2009-04-06 9:36
Re: 是因为string 的问题吗?(c语言中) 大家帮忙看看。
差不多 后天能看到 指针吧libralibra 写了:c中数组都是指针表示的ubujie 写了:libralibra 写了:c里面string是个char数组
能这样写string ***();吗?
那改成 char ? 那也不对
直接char替换不行
定义要char* score[] =...
不过 大家说的 string 是 char数组 我懂了,就像这样
char ch[10];
string s;
scanf("%s", ch);
s = ch;
谢谢大家的建议, 我先抓紧学习。