Thread: compiling with gcc in linux error

  1. #1
    Registered User
    Join Date
    Mar 2005
    Posts
    18

    Question compiling with gcc in linux error

    hi people ok??
    im from brazil and I new in here...and have one ask.
    when i compile my simple program in C(gcc in my linux) he generate one messege of erro in screen!
    Look the error:
    /****************************************/
    In function `main':
    : warning: the `gets' function is dangerous and should not be used.
    /****************************************/
    my code:
    /*****BEGIN******/
    #include<stdio.h>
    #include<stdlib.h>
    int main(){
    char *p;
    int des_char;
    printf("\nQuantos caracteres deseja digitar: ");
    scanf("%d",&des_char);
    p=malloc(des_char*sizeof(char));
    if(!p){
    printf("Erro de alocacao!\n");
    exit(1);
    }
    else printf("Alocado com sucesso!!\n");
    gets(p);
    printf("Voce alocou %d de espaco e voce digitou %s\n",sizeof(char)*des_char,p);
    return(0);
    }

    /**********************************FIM************* ************/
    If any one of your have knowledge of this error or one solution answerme please.

    Tnks!

  2. #2
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    Stock answer:Bottom line:
    the `gets' function is dangerous and should not be used
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  3. #3
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Quote Originally Posted by kermi3
    Welcome to the boards. If you haven't already done so then please take some time to familiarise yourself with the faq:
    http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

    Make sure you have a look at the the posting guidelines:
    http://cboard.cprogramming.com/annou...ouncementid=51
    Following the rules will ensure you get a prompt answer to your question.

    Remember, too, that the board has a search facility, a link is at the top of your screen:
    http://cboard.cprogramming.com/search.php
    It will often get you a quicker answer to your questions than waiting for a response to one you have posted.

    It appears that you are posting a homework assignment or other project.

    Please don't ask people to do all your work for you, See the announcement on Homework at the top of all forums to see what is acceptable or PM me. Basically people are happy to help, but they're not going to do it all for you.

    Show us what you've got, show your code (using code tags), or where you're confused and someone will be happy to help you I'm sure. If it's something that you absolutely don't understand how it works, like you have no clue how qsort works, then ask a general question about the function and I'm sure someone will explain it. Though they may not give you all of the code for it, but someone will explain the concept.


    On obivous homework questions especially, I like to remind people of the board's ninth guildeline, while this board is very helpful to people, make sure you have your instructor's permission before seeking help on assignments. While people on these boards are more than happy to help, we discourage people from asking for help on graded work without the instructor's permission, and we claim no repsonsibilty for any cheating or honor violations.

    Feel free to PM me with any questions.

    Good Luck,

    Kermi3

    Read and follow the above instructions, and try your post (in the same thread) again.

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

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. more then 100errors in header
    By hallo007 in forum Windows Programming
    Replies: 20
    Last Post: 05-13-2007, 08:26 AM
  2. Post...
    By maxorator in forum C++ Programming
    Replies: 12
    Last Post: 10-11-2005, 08:39 AM
  3. C++ compilation issues
    By Rupan in forum C++ Programming
    Replies: 1
    Last Post: 08-22-2005, 05:45 AM
  4. Learning OpenGL
    By HQSneaker in forum C++ Programming
    Replies: 7
    Last Post: 08-06-2004, 08:57 AM
  5. Couple C questions :)
    By Divx in forum C Programming
    Replies: 5
    Last Post: 01-28-2003, 01:10 AM