how to learn C?

This is a discussion on how to learn C? within the C Programming forums, part of the General Programming Boards category; Guys, some of you are expert and some still learning C...but anyway can someone write some ideas about how could ...

  1. #1
    Registered User
    Join Date
    May 2010
    Posts
    81

    how to learn C?

    Guys, some of you are expert and some still learning C...but anyway can someone write some ideas about how could i learn C? I have to lean it...but i don' t know how!!! waiting...

  2. #2
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Here's a couple of similiar but different tutorials:

    C Programming Tutorial
    The GNU C Programming Tutorial

    Pick one of those and start working thru it.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  3. #3
    Registered User
    Join Date
    May 2010
    Posts
    81

    answer

    I already have a book in C, but it is difficult...does any know how many months sb need to learn C with normal programing in the pc?

  4. #4
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    That depends. If you already have some experience in another (reasonably similiar) programming language, so you understand what functions and loops and arrays are, then you may be able to learn the basic syntax inside of a few weeks to a month.

    Outside of that, it really depends how much time you put in and how hard it is for you to grasp things like arrays, loops, and functions.

    My advice is to write lots of short experiments. Programming tends to involve a lot of typing so you might as well get used to it. If your editor/IDE does not have a feature which can do this automatically, you might want to create a file like this:
    Code:
    #include <stdio.h>
    
    int main(int argc, const char *argv[]) {
    	
    	return 0;
    }
    Call it "base.c" or something, and then everytime you want to try a fresh snippet of code, just copy that to a new file and go to work. When you have a concept or command figured out, write short simple examples demonstrating the concept, and save those with some comments under a self-explanatory name. For example:
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    /* fileread.c: reads a text file named on the command line
     * and prints it to the screen */
    
    int main(int argc, const char *argv[]) {
    	FILE *in;
    	char buffer[1024];
    
    /* check for argument */
    	if (argc < 2) {
    		puts("Filename required!");
    		return -1;
    	}
    
    /* try to open file */
    	in = fopen(argv[1],"r");
    	if (!in) {
    		perror("fopen() failed: ");
    		return -2;
    	}
    
    /* read and print out */
    	while (fgets(buffer,1024,in)) 
    		printf("%s",buffer);
    
    /* close file */
    	fclose(in);
    
    	return 0;
    }
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  5. #5
    Third Eye Babkockdood's Avatar
    Join Date
    Apr 2010
    Posts
    352
    OK. Create a new text file. Type the following into the text file.
    Code:
    #include <stdio.h>
    
    int main()
    {
         printf("Hello World!\n");
         return 0;
    }
    Save the text file as "hello.c". This is called "source code". It's a computer program that humans can read and edit. To run the program, we need to compile it. It's best to use Linux or Mac OS X to program, since they both have a built-in C compiler. Compile the source code in the Terminal. Navigate to where hello.c is saved. Type, "gcc -o hello hello.c". This will create an executable using hello.c. To run the executable, type "./hello". Your program will run, printing "Hello World!" right there, on the screen. Whenever you want to edit your source code, make sure you delete the old executable before you compile a new one.

    Here's a good book to begin learning C.

    http://www.amazon.com/Programming-La.../dp/0131103628

  6. #6
    Registered User
    Join Date
    May 2010
    Posts
    81
    Actually i am working on C for about 6-7 months...now i try to learn about files, stucks...but i found them very difficult...Should i worry, or they are not very difficult as i think????

  7. #7
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Structs are pretty important. Try and write a program using opendir(), readdir(), and stat() to read all the files in a directory and print out their name and size. This involves using some structs, and reading data in loops, probably with a short function to stat() the file and print out information. You get the name of each file from the struct dirent returned by readdir():
    Code:
    struct dirent {
          char d_name[];
          [......]
    You can then take the d_name field and get a bigger struct of file information using stat:
    Code:
    struct stat info;
    stat("filename",&info);
    printf("Size: %d bytes\n", (int)info.st_size);
    I am not sure if this is exactly the same on windows -- you should maybe put your OS and the compiler you are using in your signature here.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  8. #8
    Registered User
    Join Date
    May 2010
    Posts
    81

    aswer

    Well, i am using a partition..so i ave both ubuntu and windows 7...i believe i am totally covered

  9. #9
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    23,013
    Quote Originally Posted by Babkockdood View Post
    Save the text file as "hello.c". This is called "source code". It's a computer program that humans can read and edit.
    Yes, it's a source file, and no, it isn't a computer program.
    It is a human-readable file. That is all.

    To run the program, we need to compile it.
    You have no program. All you have are source files.
    You need a tool that takes your source code and produces a program from it. That is a compiler.

    It's best to use Linux or Mac OS X to program, since they both have a built-in C compiler.
    It is NOT best to use Linux or Mac. The operating system has nothing to do with your code. There is no such thing as best. There are compilers for almost all platforms.
    You only need to use the one you are most familiar with.

    Whenever you want to edit your source code, make sure you delete the old executable before you compile a new one.
    Unnecessary.

    As for the whole learning thing:
    There is a simple path of learning a language. This path is basically:
    - Read one or more beginner books.
    - Read one or more immediate books.
    - Read one or more expert books.
    - Practice, practice, practice.

    There is no easy way to become an expert in any language in any short amount of time and there are not shortcuts. Learn from books, tutorials and other resources. Ask if you don't understand. Assimilate all the information from the books. Do this by doing exercises with what you just learned.
    Then write programs, programs, programs and many more programs.
    All the experts on this board have become experts because they've been writing code for many, many years. You can do it, too, and you'll notice that your knowledge will grow, and one day, you, too, will be an expert.
    But also note that it isn't possible to learn everything. Even experts have things they don't know.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  10. #10
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,762
    Whenever you want to edit your source code, make sure you delete the old executable before you compile a new one.
    Unnecessary.
    Um... get confirmation from another party. IDE's make it unnecessary most of the time, but even so, sometimes you have to clean projects; if you're a minimalist, it has to be done. I think so, anyway. Makefiles probably do some magic, but I don't know.

    - Read one or more beginner books.
    - Read one or more immediate books.
    - Read one or more expert books.
    No recommendations?

    But also note that it isn't possible to learn everything. Even experts have things they don't know.
    Well, mostly agreeable, but you're allowed to specialize. And there is a keen difference between not knowing and memory lapses. [/hand-waving]

  11. #11
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    23,013
    Quote Originally Posted by whiteflags View Post
    Um... get confirmation from another party. IDE's make it unnecessary most of the time, but even so, sometimes you have to clean projects; if you're a minimalist, it has to be done. I think so, anyway. Makefiles probably do some magic, but I don't know.
    Cleaning projects often means removing temporary files spawned by the compiler. Deleting the executable is not necessary. You can just overwrite it.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. You have to learn C in order to learn C++
    By gandalf_bar in forum A Brief History of Cprogramming.com
    Replies: 20
    Last Post: 07-16-2004, 11:33 AM
  2. Quickly learn C# for a C++ expert
    By BigDaddyDrew in forum C# Programming
    Replies: 9
    Last Post: 06-06-2004, 05:38 PM
  3. The best place to learn
    By CougarElite in forum C Programming
    Replies: 15
    Last Post: 04-25-2004, 05:07 PM
  4. Novice trying to learn C++
    By dead in forum C++ Programming
    Replies: 10
    Last Post: 12-01-2003, 09:25 PM
  5. Wanna learn Assembly?
    By Garfield in forum A Brief History of Cprogramming.com
    Replies: 137
    Last Post: 06-29-2002, 02:49 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21