fopen里面的绝对路径怎么写?

系统安装、升级讨论
版面规则
我们都知道新人的确很菜,也喜欢抱怨,并且带有浓厚的Windows习惯,但既然在这里询问,我们就应该有责任帮助他们解决问题,而不是直接泼冷水、简单的否定或发表对解决问题没有任何帮助的帖子。乐于分享,以人为本,这正是Ubuntu的精神所在。
回复
hanis_ghost
帖子: 41
注册时间: 2015-06-19 21:16

fopen里面的绝对路径怎么写?

#1

帖子 hanis_ghost » 2017-11-28 14:06

比如打开 软件源

代码: 全选

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<ctype.h>

void main(int argc,char* argv[])
{
	FILE* fp=fopen("/etc/apt/source.list","r");
	char c;
	while((c=getc(fp))!='\0')
		putc(c,stdout);
}
有什么错误?谢谢
头像
astolia
论坛版主
帖子: 6396
注册时间: 2008-09-18 13:11

Re: fopen里面的绝对路径怎么写?

#2

帖子 astolia » 2017-11-28 18:57

还没学会调试?连问题出在哪里都不知道。
另外你该好好买本c编程的教程来看了,一堆基础错误,即使是学谭浩强那本问题一堆的书都不会错成这个样子

代码: 全选

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<errno.h>

int main(int argc,char* argv[]) {
   FILE* fp=fopen("/etc/apt/sources.list","r");
   if (fp == NULL) {
	   perror("fopen");
	   return 1;
   }
   int c;
   while((c=getc(fp))!=EOF) {
      putc(c,stdout);
   }
   return 0;
}
回复