₦airaland Forum

Welcome, Guest: RegisterLoginWith GoogleTrendingRecentNew

Stats: 3,327,357 members, 8,430,645 topics. Date: Saturday, 20 June 2026 at 07:55 PM

Toggle theme

Help With C I/o Code - Programming - Nairaland

Nairaland ForumScience/TechnologyProgrammingHelp With C I/o Code (935 Views)

1 Reply (Go Down)

Help With C I/o Code by Fayimora(op): 2:03pm On Jul 11, 2011
Hey guys can someone help me with this c code? It reads a fils and prints its contents on the screen. i wrote it last yr wen i was learning c and now i can't remember what happens where, Thanks

/* Program to display the contents of a file on screen */
#include <stdio.h>
int main(void)
{
FILE *fopen(), *fp;
int c;
fp = fopen("data.txt","r"wink;
c = getc(fp) ;
while (c != EOF)
{
putchar(c);
c = getc(fp);
}
fclose(fp);
return 0;
}

Thanks in advance
Re: Help With C I/o Code by Nobody:
Re: Help With C I/o Code by Ghenghis(m): 7:24pm On Jul 11, 2011
first rule of programming, "thou shalt debug thy own code"!

/* Program to display the contents of a file on screen */
#include <stdio.h>
int main(void)
{
//declare pointers file
FILE *fopen(), *fp;
int c;
//open file for read access
fp = fopen("data.txt","r"wink;
//read a character
c = getc(fp) ;
while (c != EOF)//while character is not end of file sentinel continue
{
putchar(c);//print character
c = getc(fp); // read next character
}
fclose(fp); //close file
return 0;
}
Re: Help With C I/o Code by Fayimora(op): 7:33pm On Jul 11, 2011
@omo_to_dun. Explain. @ghenghis thanks. Already carped bombed it with debugging statements wen i ddnt get a quick reply. Thanks anyways
Re: Help With C I/o Code by Nobody:
Re: Help With C I/o Code by Fayimora(op): 8:29pm On Jul 11, 2011
Am revisiting c, A lil bit easy cause i do objective-c
Re: Help With C I/o Code by Nobody:
Re: Help With C I/o Code by Fayimora(op): 8:51pm On Jul 11, 2011
hhehhehe cool. Am looking for some video tutorials but cant find any. Its a lil bit as interesting as ma almighty perl :d
Re: Help With C I/o Code by Nobody:
Re: Help With C I/o Code by Fayimora(op): 10:47pm On Jul 11, 2011
omo_to_dun:
My brother, I do not f*ck with Perl; although that language can do anything you can imagine, it is too clumsy for me. The new Perl 6 is also adding functional language constructs to its already diverse repertoire. But when it comes to string processing, I hear Perl is king.
Lolzz yeah perl is kinda clumsy even very ugly but trust me, i have gained a lot from it, Made some scripts that just makes ma life easy.One problem with perl is that its hard to learn but you only learn it once and you become a boss. Take for example, when i write code for someone(say a mini-software with 6 classes in Java). I don't have to go through each code to place the header licence,  all i do is write a 4 line script to do the jon in less than a second. Perl is just the bomb. The only thing i still haven't gotten an answer to is "Perl and Ruby, which is better?".
1 Reply

Google I/O 2015[google I/O] Google Introduces Native Client, Add C And C++ Code Web AppsWhat Is The Relationship Between Processor And I/o Device234

I Need A Detailed And Expert Help In Explanation Of Classes And Objects In C++If You Have Passion For OOP Is Different To You Want To Learn Or Know OOPMeet Joe Green, The Guy Who Walked Away From $17B Facebook Fortune