Thread: dev c compiler problem

  1. #1
    Registered User
    Join Date
    Sep 2009
    Posts
    1

    dev c compiler problem

    while installing the dev c set up i got a message that it was not able to include some lib and some include files and that this can create problem during compilation. it asked whether i wanted to continue installing. i clicked yes.
    now when i run a simple program which uses only gets and puts, it doesnt input the string and after some debugging, i found that it reports access violation compilation error.

    #include<stdio.h>
    #include<conio.h>
    #include<stdlib.h>
    #include<string.h>
    int flag,n;
    struct node
    {
    char *word;
    struct node *left;
    struct node *right;
    };
    struct node *root;
    char *w,*line;
    struct node *addtree(struct node *p,char *s)
    {
    if(p==NULL)
    {
    p->word=s;
    p->left=NULL;
    p->right=NULL;
    }
    else if(strcmp((p->word),s)>0)
    p->left=addtree(p->left,s);
    else
    p->right=addtree(p->right,s);
    return p;
    }
    int comp(char *u)
    {
    int i=0;
    // flag=1;
    while(i<n)
    {
    if(u[i]!=line[i])
    {
    // flag=0;
    return 0;
    }
    i++;
    }
    if(u[n]!=line[n])
    return 1;
    else
    return 0;
    }
    void traverse2(struct node *t)
    {
    if(strlen(t->word)>n)
    traverse2(t->left);
    if(comp(t->word))
    puts(t->word);
    traverse2(t->right);
    }
    void traverse1(struct node *p)
    {
    if(p!=NULL)
    traverse1(p->left);
    line=p->word;
    traverse2(root);
    traverse1(p->right);
    }
    int main()
    {
    root=NULL;
    //w=NULL;
    printf("enter words");
    fflush(stdin);
    gets(w);
    // printf("\ngets(w)=:%d",gets(w));
    //while(gets(w)!=NULL)
    //root=addtree(root,w);
    printf("\nenter n");
    scanf("%d",&n);
    //traverse1(root);
    printf("*w=\n");
    puts(w);
    getch();
    return 0;
    }
    here is my code which i have reduced by including the function calls in comments

  2. #2
    Registered User
    Join Date
    Oct 2006
    Location
    Canada
    Posts
    1,243
    Quote Originally Posted by manu01 View Post
    after some debugging, i found that it reports access violation compilation error. ...
    your using "gets" on some "random" memory address which you havent allocated, so you're not allowed to write there. you need to allocate some space, like "char w[some_size]" instead of "char *w" and not doing anything with it before using it. also, see below

    Quote Originally Posted by manu01 View Post
    Code:
    ...
    char *w,*line;
    ...
    
    int main()
    {
         fflush(stdin);
         gets(w);    
         ...
    }
    - Why fflush(stdin) is wrong
    - Why gets() is bad / Buffer Overflows

    ive only looked at the start of your code and saw these 2 problems, so ill let you fix them and make sure they dont exist elsewhere in your program. after you've fixed and verified this, let us know your other issues if any.
    Last edited by nadroj; 09-25-2009 at 10:16 PM. Reason: spacing

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Weird compiler (Dev)
    By gavra in forum C Programming
    Replies: 11
    Last Post: 08-03-2008, 01:19 AM
  2. Starting with Dev C ; a problem
    By mabauti in forum C++ Programming
    Replies: 18
    Last Post: 12-05-2007, 11:16 AM
  3. added start menu crashes game
    By avgprogamerjoe in forum Game Programming
    Replies: 6
    Last Post: 08-29-2007, 01:30 PM
  4. Dev C++ Compiler - True or false?
    By JamesF in forum A Brief History of Cprogramming.com
    Replies: 6
    Last Post: 07-10-2006, 11:03 AM
  5. Comile problem using latest Dev C++ Compiler
    By shiny_dico_ball in forum C++ Programming
    Replies: 6
    Last Post: 06-06-2003, 05:32 PM

Tags for this Thread