i have just started learning assembly and c could anybody please :( tell some good books on them especially C i am having problem in c i am new here does any body know good thread on AO about C
Printable View
i have just started learning assembly and c could anybody please :( tell some good books on them especially C i am having problem in c i am new here does any body know good thread on AO about C
Hi
"let us C by yeshvant kanetker" is the best book for newbs starting C
and "IBM PC Assembly Language and Programming by Peter Abel" for assembly
hi wolverine
i know a bit of C , i am not a absolute newb in C. i want a good book that explains Disk I/O in C :)
I think the Book " let us C" is good for both students and advanced programmer alike i always refer to the for C
could u help me out here i have this school assignment coming could u please explain Disk I/O a bit give example code or something
I'd advise purchasing/borrowing "The C Programming Language" (Kernighan and Ritchie) otherwise known as the K&R book. It covers I/O for files as well as low-level access in Unix and is *the* C reference book.
this program will read a file and count how many characters, spaces and newlines are present in a file
[quote]
#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);
}[\quote]
haven't compiled but it should work let me know if it dosen't or u don't understand anything
what is this FILEQuote:
before a file could be read or written it must be opened. opening a file establishes a link between the program and the operationg system. the link between our prog and the OS is a structure called FILE which has been defined in the header "stdio.h". we request the OS to open a file and what we get back is a pointer to the structure FILE. that is why we make the following dec.Quote:
FILE *fp;
i can understand the rest of the code except
fp is the file pointer what does fopen() doQuote:
fp=fopen("Test","r");
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
Brginning C Programming by Ivor Horton (Wrox) is a great book. I learned from that. Excuse the absence of int main though.
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 ] :
Assembly do they even use that as much as they did before ?Quote:
C How to Program
Fourth Edition
© 2004
ISBN: 0131426443
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..
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
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.Quote:
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
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;
}