Thread: Quick Segmentation Fault

  1. #1
    C Beginner
    Join Date
    Dec 2011
    Location
    Portugal
    Posts
    187

    Quick Segmentation Fault

    Hey guys, I'm getting a segmentation fault and I have no idea why.

    Code:
    adicionavertice (GRAFO *g)
    { int adicionainteiro;
      char condi[50];
      printf("Qual e o numero do vertice que pretende adicionar ?\n");
      scanf("%d",&adicionainteiro);
      printf("Qual e a condicao que pretende ter associada a este vértice ?\n");
      scanf("%s",condi);
      printf("que rei");
    This is the output :
    Code:
    Qual e o numero do vertice que pretende adicionar ?
    2
    Qual e a condicao que pretende ter associada a este vértice ?
    x0>0
    Segmentation fault.

  2. #2
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    If you have no idea why there's a seg fault, why do you think that is all of the relevant code?

    Note that printf uses stdout which is buffered, meaning the seg fault could be after this line:
    Code:
      printf("que rei");
    But before stdout is flushed and "que rei" is displayed. To avoid buffering for debugging purposes, use fprintf(stderr, ...).
    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

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Segmentation Fault Help
    By DuckCowMooQuack in forum C Programming
    Replies: 2
    Last Post: 02-08-2011, 02:16 AM
  2. Segmentation fault?
    By Camambert in forum C++ Programming
    Replies: 2
    Last Post: 08-20-2009, 11:21 AM
  3. Why am I getting segmentation fault on this?
    By arya6000 in forum C++ Programming
    Replies: 6
    Last Post: 10-12-2008, 06:32 AM
  4. Quick Question about Segmentation fault
    By vutek0328 in forum C Programming
    Replies: 4
    Last Post: 08-14-2006, 04:19 PM
  5. segmentation fault and memory fault
    By Unregistered in forum C Programming
    Replies: 12
    Last Post: 04-02-2002, 11:09 PM