Thread: Age of C

  1. #1
    Registered User
    Join Date
    Jun 2006
    Posts
    9

    Question Age of C

    Is C different today than it was 1996?
    I´m wondering cuz i have a book from that year and most of the tutorials don´t work.

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >Is C different today than it was 1996?
    Yes and no. A new standard was ratified in 1999, but it's not widely implemented yet. So we continue to use the language definition set in place in 1990.

    >I´m wondering cuz i have a book from that year and most of the tutorials don´t work.
    It's more likely that your book uses tons of non-portable stuff that doesn't work anymore. What book, what compiler, and show us an example program.
    My best code is written with the delete key.

  3. #3
    Registered User
    Join Date
    Jun 2006
    Posts
    9
    this program does´nt work and it´s the easiest one:
    Code:
    #include <stdio.h>
    main ( )
    {
         printf("Hello world!\n");
    }
    when i run this i just recieves error messages

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Well it's time you started reading them. They're there for a reason. Take the first one, fix it, recompile. Repeat until you have no warnings or errors.


    Quzah.
    Hope is the first step on the road to disappointment.

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > when i run this i just recieves error messages
    You still didn't say what book or what compiler.
    And now I'll add "what error messages"

    Please don't tell me you're using that piece of crap known as miracle c
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  6. #6
    Registered User
    Join Date
    Jun 2006
    Posts
    9
    here´s another one that´s don´t working:
    Code:
    #include <stdio.h>
    #include <stdlib.h>   /* För calloc */
    #include <string.h>   / För strdup */
    
    
       /* Här deklareras en datastruktur */
    struct kompis {
       char* namn;            /* namn på en vän */
       unsigned char alder;   /* Ålder          */
       struct kompis* nesta;  /* Nästa struct   */
    };
    
    
       /*Funktionsdeklarationer */
    struct kompis* Nykompis(const char* namn);
    struct kompis* SorteraIn(struct konmpis* ny,
                    const struct kompis* rot);
    void Visapolare(const struct kompis* rot);
    
    
    /*om denna funktion inte finns i STRING.H */
    /* char* strdup(char* orig);  */
    I use Bloodshev dev c++, and borland c++. the error messages is:3:23 C:\Dev-Cpp\Daniels test.c [Warning] extra tokens at end of #include directive
    17 C:\Dev-Cpp\Daniels test.c [Warning] "struct konmpis" declared inside parameter list
    17 C:\Dev-Cpp\Daniels test.c [Warning] its scope is only this definition or declaration, which is probably not what you want
    [Linker error] undefined reference to `WinMain@16'
    17 C:\Dev-Cpp\Daniels test.c ld returned 1 exit status
    And the book is: Lättpocket om c-programmering it´s swedish...

  7. #7
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    Code:
    #include <string.h>   / För strdup */
    should be
    Code:
    #include <string.h>   /*För strdup */
    Kurt

  8. #8
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    1. strdup() isn't a standard function.
    It might work fine for you at the moment, but expect surprises if you move to another OS/Compiler.

    2. Check your spelling
    struct kompis* SorteraIn(struct konmpis* ny

    3. [Linker error] undefined reference to `WinMain@16'
    You have a main(), for a console project
    You set up a gui project, which expects winMain()
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  9. #9
    Registered User
    Join Date
    Mar 2006
    Posts
    725
    @Salem (3): He's using Dev-C++, which means he's using MinGW. MinGW does throw that error when you do not define main().

    Maybe you'd want to check out the cprogramming.com online tutorials, they are written by our own members and all feature standard code.

    And most of them are warnings. Not that you shouldn't ignore them, but they will not cause the compiler to stop. Heck, your code compiles properly. But it does not link because you do not define main(). And the program will do nothing in any case.

    Looks like a linked list implementation to me.
    Code:
    #include <stdio.h>
    
    void J(char*a){int f,i=0,c='1';for(;a[i]!='0';++i)if(i==81){
    puts(a);return;}for(;c<='9';++c){for(f=0;f<9;++f)if(a[i-i%27+i%9
    /3*3+f/3*9+f%3]==c||a[i%9+f*9]==c||a[i-i%9+f]==c)goto e;a[i]=c;J(a);a[i]
    ='0';e:;}}int main(int c,char**v){int t=0;if(c>1){for(;v[1][
    t];++t);if(t==81){J(v[1]);return 0;}}puts("sudoku [0-9]{81}");return 1;}

  10. #10
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > But it does not link because you do not define main().
    The linker error would be undefined reference to main if that were the case.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  11. #11
    Registered User
    Join Date
    Jun 2006
    Posts
    9
    Code:
    #include <stdio.h>
    #include <stdlib.h>   /* För calloc */
    #include <string.h>   /* För strdup */
    
    
       /* Här deklareras en datastruktur */
    struct kompis {
       char* namn;            /* namn på en vän */
       unsigned char alder;   /* Ålder          */
       struct kompis* nesta;  /* Nästa struct   */
    };
    
    
       /*Funktionsdeklarationer */
    struct kompis* Nykompis(const char* namn);
    struct kompis* SorteraIn(struct kompis* ny,
                    const struct kompis* rot);
    void Visapolare(const struct kompis* rot);
    
    
    /*om denna funktion inte finns i STRING.H */
    /* char* strdup(char* orig);
    Now i just get this error: 22:1 C:\Dev-Cpp\Untitled1.c unterminated comment

  12. #12
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    Code:
    /* char* strdup(char* orig); */

  13. #13
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > /* char* strdup(char* orig);
    Can you spot the closing comment on this line?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  14. #14
    Registered User
    Join Date
    Jun 2006
    Posts
    9
    Code:
    #include <stdio.h>
    #include <stdlib.h>   /* För calloc */
    #include <string.h>   /* För strdup */
    
    
       /* Här deklareras en datastruktur */
    struct kompis {
       char* namn;            /* namn på en vän */
       unsigned char alder;   /* Ålder          */
       struct kompis* nesta;  /* Nästa struct   */
    };
    
    
       /* Funktionsdeklarationer */
    struct kompis* Nykompis(const char* namn);
    struct kompis* SorteraIn(struct kompis* ny,
                    const struct kompis* rot);
    void Visapolare(const struct kompis* rot);
    
    
    /*om denna funktion inte finns i STRING.H */
    /* char* strdup(char* orig);  */
    I fixed the code like you said and now i get this error: [Linker error] undefined reference to `WinMain@16'
    ld returned 1 exit status
    C:\Dev-Cpp\Makefile.win [Build Error] [Project2.exe] Error 1

  15. #15
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    That's because there is no main() function.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Calc age use Date of PC
    By miziri in forum C++ Programming
    Replies: 12
    Last Post: 03-18-2006, 05:01 AM
  2. wow...technology today...
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 29
    Last Post: 02-01-2003, 07:37 PM
  3. Information Age
    By Megatron in forum A Brief History of Cprogramming.com
    Replies: 11
    Last Post: 11-24-2002, 11:39 PM
  4. Age in Minutes
    By harryP in forum C++ Programming
    Replies: 7
    Last Post: 09-09-2002, 10:40 PM
  5. How to calc. your age in days..?
    By Gugge in forum C Programming
    Replies: 7
    Last Post: 03-13-2002, 03:40 AM