OpenVZ Forum


Home » General » Support » URGENT ... Segmentation fault in program... Pls help
URGENT ... Segmentation fault in program... Pls help [message #9698] Wed, 17 January 2007 19:50 Go to next message
turkish_van is currently offline  turkish_van
Messages: 1
Registered: January 2007
Junior Member
I have currently this C program that always gives me segmentation fault when executed.
============================================================ ====

#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<strings.h>

typedef struct amino{
char seq;
struct amino *before;
struct amino *after;
}AMINO;

int main (void)
{FILE *data, *output, *output1;
data = fopen ("Sample.txt", "r");
output = fopen ("output_sample1.txt","w");
output1 = fopen ("output_sample2.txt","w");
char input[100] = {};
AMINO *ptr;
AMINO *start;
AMINO *start1;
AMINO *next;
AMINO *pop;
AMINO *pop1;

while (fgets(input,100,data)!= NULL)
{ if (strstr(input, "SQ SEQUENCE " ) != NULL)
{ fprintf (output, "=================================\n");
start = malloc (sizeof (AMINO));
start1 = start;
start->before = NULL;
start->after = NULL;
while ( (start->seq = fgetc (data)) != '/')
{ fprintf (output, "%c", start->seq);
if (start->seq == ' ' || start->seq == '\n')
{ fprintf(output,"_");
(AMINO*)pop = (AMINO*)start;
(AMINO*)pop1 = (AMINO*)start->before;
start = (AMINO*)pop1; start->after = NULL;
free(pop);
}
next = malloc (sizeof(AMINO));
start->after = next;
next->before = start;
start = next;
start->after = NULL;
}
ptr = start1;
while(ptr->after != NULL)
{fprintf (output1, "%c", ptr->seq);
ptr = ptr->after;
}
fprintf(output1, "\n==============================\n");
free (start1);
}
}
fclose (data);
fclose (output);
fclose (output1);
return EXIT_SUCCESS;
}

========================================================
This file actually reads a file and removes subsequent new line characters and spaces. However, i had segmentation fault in the line "start = (AMINO*)pop1;" ... May i know what is wrong here and how can i change it ?
Thank you
  • Attachment: read_sprot1.c
    (Size: 2.00KB, Downloaded 221 times)
  • Attachment: Sample1.txt
    (Size: 8.13KB, Downloaded 252 times)
Re: URGENT ... Segmentation fault in program... Pls help [message #9699 is a reply to message #9698] Wed, 17 January 2007 19:57 Go to previous messageGo to next message
kir is currently offline  kir
Messages: 1645
Registered: August 2005
Location: Moscow, Russia
Senior Member

I can't get how it is related to OpenVZ. Can you give me a hint?

Kir Kolyshkin
http://static.openvz.org/userbars/openvz-developer.png
Re: URGENT ... Segmentation fault in program... Pls help [message #9701 is a reply to message #9699] Wed, 17 January 2007 20:30 Go to previous message
dlzinc
Messages: 34
Registered: March 2006
Member
Because it segfaults when you run it under OpenVz!
(and just so happens to also segfault when you don't...)

Anyways, it sounds like somebody thought this was a homework help forum...
Previous Topic: Linux Stable
Next Topic: *SOLVED* Installation on Debian - VFS: Cannot open root device
Goto Forum:
  


Current Time: Fri Nov 15 21:12:52 GMT 2024

Total time taken to generate the page: 0.03379 seconds