C 从从命令行打开的.txt文件中读取整数
我需要从从命令行打开的.txt文件中读取一个整数,如下所示:C 从从命令行打开的.txt文件中读取整数,c,input,C,Input,我需要从从命令行打开的.txt文件中读取一个整数,如下所示: myprogram < input.txt #包括 int main(){ int n; scanf(“%d”和“&n”); scanf(“%*[^\n]”;//跳过注释 字符字[n][16]; int i; 对于(i=0;i
myprogram < input.txt
#包括
int main(){
int n;
scanf(“%d”和“&n”);
scanf(“%*[^\n]”;//跳过注释
字符字[n][16];
int i;
对于(i=0;i
您能否展示包含scanf()
的程序,并说明其不起作用的原因?
5 //number of following words
word1
word2
word3
word4
word5
#include <stdio.h>
int main(){
int n;
scanf("%d", &n);
scanf("%*[^\n]");//skip comment
char word[n][16];
int i;
for(i = 0;i < n; ++i){
scanf("%15s", word[i]);
}
for(i = 0;i < n; ++i){
printf("%s\n", word[i]);
}
return 0;
}