|
-
December 29th, 2003, 09:02 PM
#11
Senior Member
fp=fopen("test","r");
fp is a pointer which cntains the address of the structure FILE which has been defined in the header file "stdio.h"
fopen() will open the file "test" in read mode which tells the C compiler that we would be reading the contents of the file. 'r' is a file opening mode
once the file has been opened for reading using fopen() the file's contents are brought into the main memory and a pointer to the first character. to read the fole's contents from the memory there is the function "fgetc()"
ch=fgets(fp);
fgets() reads the character from current pointer position, advances to the next character and reads it, which we have collected in the variable "ch". "fp" is the file pointer.
rest of it i think u could easily understand
-
December 29th, 2003, 11:06 PM
#12
Senior Member
-
December 29th, 2003, 11:52 PM
#13
Junior Member
Brginning C Programming by Ivor Horton (Wrox) is a great book. I learned from that. Excuse the absence of int main though.
-
December 30th, 2003, 06:41 AM
#14
Check this site out these guys have good programming books there expesive though. But worth the money in my opinion.
Deitel & Associates, Inc.
They should have what you are looking for. You can also find their books on Amazon.com as well if you do a search for the title of the book. Hope that helps.
You should also join a mailing list or maybe even a newsgroup like - comp.lang.c there's a lot of people there that can help you. Another things as well would be too look for people in your area who know C or have a good understanding of it.
Here is a book from their website which is coming out this year [ Might just be what you are looking for ] :
C How to Program
Fourth Edition
© 2004
ISBN: 0131426443
Assembly do they even use that as much as they did before ?
-
December 30th, 2003, 11:01 AM
#15
hmm..I know 'let us c''s pretty good w0lverine..but there's only one chapter on disk I/O operations n such...try the 'Big Black Book of C' or "the Complete C reference"..I think its a TMH publication neemitjamwal...hope this helps..
-
December 30th, 2003, 11:30 AM
#16
Senior Member
There 's a lot of tutorials available on-line, you may try to look at it. Just the proper key word.
That's all.
JohnHACK
-
January 3rd, 2004, 06:40 AM
#17
Originally posted here by w0lverine
this program will read a file and count how many characters, spaces and newlines are present in a file
Code:
#include "stdio.h"
void main()
{
FILE *fp;
char ch;
int nol=0, not=0,nos=0,noc=0;
fp=fopen("Test","r");
while(1)
{
ch=fgetc(fp);
if(ch==EOF)
break;
noc++;
if(ch=="")
nob++;
if(ch='\n')
nol++;
if(ch=='\t')
not++;
}
fclose(fp);
printf("\nNumber of characters=%d",noc);
printf("\nNumber of blanks=%d",noc);
printf("\nNumber of tabs=%d",noc);
printf("\nNumber of lines=%d",noc);
}
haven't compiled but it should work let me know if it dosen't or u don't understand anything
It doesn't work, and even if it compiled, it wouldn't perform as advertised, there are far more efficient and functional ways of going about this. You'd do well to look into switch statements and such.
Proper, functioning version:
Code:
#include <stdio.h>
#define END_OF_LINE_CHAR = '\n';
int main() {
char ch;
FILE *fp;
int num_chars = 0;
int num_spaces = 0;
int num_lines = 0;
if (! fp=fopen("Test","r")) {
printf("Failed to open file!\n");
exit(1);
}
while (ch = fgetc(fp)) {
switch (ch) {
case ' ':
num_spaces++;
break;
case END_OF_LINE_CHAR:
num_lines++;
break;
default:
num_chars++;
break;
}
}
printf("Spaces: %d, Characters: %d, Lines: %d\n", num_spaces, num_chars, num_lines);
return 0;
}
Chris Shepherd
The Nelson-Shepherd cutoff: The point at which you realise someone is an idiot while trying to help them.
\"Well as far as the spelling, I speak fluently both your native languages. Do you even can try spell mine ?\" -- Failed Insult
Is your whole family retarded, or did they just catch it from you?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|