c primer plus 一道练习题,求助 - C/C++ / C语言
题目是:编写一段程序,依次在屏幕上显示命令行中列出的所有文件。使用argc控制循环
(Write a program that sequentially displays onscreen all the files listed in the command line. Use argc to control a loop.)
几乎是照抄网上的练习源代码,但结果是错的
C/C++ code:
1 #include <stdio.h>
2 #include <stdlib.h>
3
4
5 int main(int argc,char *argv[])
6 {
7 int byte;
8 FILE *source;
9 int filect;
10
11 if(argc==1)
12 {
13 printf("Usage: %s filename[s]\n",argv[0]);
14 exit(EXIT_FAILURE);
15 }
16
17 for(filect=1;filect<argv;filect++)
18 {
19 if((source=fopen(argv[filect],"r"))==NULL)
20 {
21 printf("Counld not open file %s for input\n",argv[filect]);
22 continue;
23 }
24
25 while((byte==getc(source))!=EOF)
26 {
27 putchar(byte);
28 // putc(byte,stdout);
29 }
30
31 if(fclose(source)!=0)
32 {
33 printf("Counld not close file %s\n",argv[1]);
34 }
35 }
36 return 0;
ubuntu下运行结果为
C/C++ code
��������������ʏ
相关问答:
写了个测试程序如下
struct hostent *hp;
char AlarmDevIP[20];
int x2;
hp = gethostbyname("www.google.com");
if (hp)
{
......
如题,C/C++中的execl怎么调用写好的java程序,
execl("/opt/java1.5/bin/java","MyClass",NULL);
这样的不行哦。
不会.
运行java程序
找工具查看一下那个程序的命令行
搜索下:jni ......
在根目录/lib中存放一个log.c,log.h,并用下面的语句:
gcc -c log.c
ar crv liblog.a log.o
编译出一个liblog.a静态库,然后在文件夹:/testfile中创建一个test.c和testc.c,test.c中引用了testc.c中定义的方法 ......
如何将一个ListBox中的数据存在数据库中的一个字段下面,并且每条记录的字符串个数不一定 以及如何从数据库中读取该ListBox中的所有记录
C/C++ code:
//存入数据库
void __fastcall TForm1::Button5Click(TO ......