【发布时间】:2014-10-13 19:30:54
【问题描述】:
读行时好像有错误
状态 10
如何将数字 10 保存为整数名称状态?最后我会再读三行%c %i,这样我就可以再保存三个变量。 fscanf 比 strtok 更易于使用。
#include <stdio.h>
#include <stdlib.h>
//any?
///
/// main function
/// @author jw
/// @param
/// @param
/// @returns
///
int main(int argc, char* argv[])
{
FILE *fp;
fp = fopen( argv[1], "r" );
if( fp == NULL ) {
//something went wrong
perror( argv[1] );
exit( 1 );
}
int states = 0;
//print the first 3 lines using sscanf()
// then capitalize on that matrix
//
fscanf(fp, "%i",&states );
printf("Number found is %i", &states);
}
编译器输出:
tokenize.c: In function 'main':
tokenize.c:33:3: warning: format '%i' expects argument of type 'int', but argument 2 has type 'int *' [-Wformat=]
printf("Number found is %i", &states);
^
tokenize.c:14:14: warning: unused parameter 'argc' [-Wunused-parameter]
int main(int argc, char* argv[])
^
gcc -ggdb -Wall -std=c99 -pedantic -Wextra -o tokenize tokenize.o
【问题讨论】:
-
现在代码只打印“状态数为0”
-
我读到的那一行应该是States 10,我不知道如何选择int 10所以我把代码改成了fscanf(fp, "%c%i, letter, &states); 和添加字符;
-
这些 cmets 是什么意思?能否请您留在主题上。
-
是的,我会在 2 分钟内更新问题。
-
不,请不要那样做。你问了这个问题。请让我们留在主题上并处理您提出的问题。