hi
I already write a database program in c and it is working fine. I change some modifications in the structure which holds the data in the database in that i got segmentation fault. the code is like this
struct student
{
int a;
char n[50];
student *nxt;
};
struct dummy
{
int a;
char n[50];
}
main()
{
student *head;
read(&head);
}
void read(student *head)
{
FILE *fp;
dummy s;
student *temp;
fp = fopen("trial.txt","rb");
while( fread(&s,sizeof(dummy),1,fp))
{
temp->a = s.a;
strcpy(temp->n,s.n);
temp->nxt = malloc(sizeof(student));
temp = temp->nxt;
}
fclose(fp);
}
the above code is working fine
but instead of int a in structure student if i place char p[20] reading from file gives segmentation fault. I write to file using fwrite function. But if i create pointer
instead of variable for struct dummy the problem solves i.e if write below code for reading it works.
void read(student *head)
{
FILE *fp;
dummy *s;
student *temp;
fp = fopen("trial.txt","rb");
while( fread(&s,sizeof(dummy),1,fp))
{
temp->a = s->a;
strcpy(temp->n,s->n);
temp->nxt = malloc(sizeof(student));
temp = temp->nxt;
}
fclose(fp);
}
If any body know the reason please tell me. If u dont understand my problem i will send total code to ur mail id if u give ur mail id .
thank u
regards
n s n reddy
11 1540
hi
I already write a database program in c and it is working fine. I change some modifications in the structure which holds the data in the database in that i got segmentation fault. the code is like this
struct student
{
}
Hi Satya,
Please give full code and give some details regarding problem.
Regards
Hi Satya,
Please give full code and give some details regarding problem.
Regards
please give me ur mail id because code is in my pc but i am contacting u from my office system.
please give me ur mail id because code is in my pc but i am contacting u from my office system.
I am sorry as I cannot give my mail id. It's also against forum rules being a member of TSDN. Your problem and solution can help many others on this forum. You better post your code snippet so others can also help you and refer your post.
Best regards,
Zodilla
I am sorry as I cannot give my mail id. It's also against forum rules being a member of TSDN. Your problem and solution can help many others on this forum. You better post your code snippet so others can also help you and refer your post.
Best regards,
Zodilla
Ya, i would like to learn from this problem too.
I am sorry as I cannot give my mail id. It's also against forum rules being a member of TSDN. Your problem and solution can help many others on this forum. You better post your code snippet so others can also help you and refer your post.
Best regards,
Zodilla
Actually it is a project the code is in totally 4 files can i paste all four files code here.
hi,
I think you have not allocated for temp object. allocate using calloc or malloc.
if u declare a pointer you need to allocate memory before using it.
Thnks and Regards
xoinki
hi,
I think you have not allocated for temp object. allocate using calloc or malloc.
if u declare a pointer you need to allocate memory before using it.
Thnks and Regards
xoinki
After allocating the memory to the pointer the problem was solved but my problem is when i am using a variable then only i get the segmentation problem
hi,
Whether "p[20]" is enough? if u write more than 20 bytes.. obviously the program gives segmentation fault. I would suggest you to change all arrays to pointers then allocate, copy and finally cleanup module to free all loopin throgh the linked list.
Regards
Xoinki
hi,
Whether "p[20]" is enough? if u write more than 20 bytes.. obviously the program gives segmentation fault. I would suggest you to change all arrays to pointers then allocate, copy and finally cleanup module to free all loopin throgh the linked list.
Regards
Xoinki
In p[20] i am using only 10 bytes. and the problem is while i am writing these records into the file using fread or fwrite here the program terminates with segmentation fault
hi,
dont u think this , -
while( fread(&s,sizeof(dummy),1,fp))
-
should be -
while( fread(&s,sizeof(dummy),1,fp) != EOF)
-
Regards,
Xoinki
hi,
dont u think this , -
while( fread(&s,sizeof(dummy),1,fp))
-
should be -
while( fread(&s,sizeof(dummy),1,fp) != EOF)
-
Regards,
Xoinki
ThankQ i will try it
Sign in to post your reply or Sign up for a free account.
Similar topics
by: sivignon |
last post by:
Hi,
I'm writing a php script which deals with 3 ORACLE databases.
This script is launch by a script shell on an linux machine like this :
/../php/bin/php ./MySript.php (PHP 4.3.3)
My script...
|
by: diyanat |
last post by:
i am writing a cgi script in C using the CGIC library, the script
fails to run, i am using apache on linux
error report from apache : internal server error
Premature end of script headers:...
|
by: laberth |
last post by:
I've got a segmentation fault on a calloc and I don'tunderstand why?
Here is what I use :
typedef struct noeud {
int val;
struct noeud *fgauche;
struct noeud *fdroit;
} *arbre; //for those...
|
by: Zheng Da |
last post by:
Program received signal SIGSEGV, Segmentation fault.
0x40093343 in _int_malloc () from /lib/tls/libc.so.6
(gdb) bt
#0 0x40093343 in _int_malloc () from /lib/tls/libc.so.6
#1 0x40094c54 in malloc...
|
by: Fra-it |
last post by:
Hi everybody,
I'm trying to make the following code running properly, but I can't get
rid of the "SEGMENTATION FAULT" error message when executing.
Reading some messages posted earlier, I...
|
by: Digital Puer |
last post by:
Hi, I'm coming over from Java to C++, so please bear with me.
In C++, is there a way for me to use exceptions to catch
segmentation faults (e.g. when I access a location off
the end of an array)?...
|
by: Paminu |
last post by:
I have a wierd problem.
In my main function I print "test" as the first thing. But if I run the call
to node_alloc AFTER the printf call I get a segmentation fault and test is
not printed!
...
|
by: pycraze |
last post by:
I would like to ask a question. How do one handle the exception due to
Segmentation fault due to Python ? Our bit operations and arithmetic
manipulations are written in C and to some of our...
|
by: madunix |
last post by:
My Server is suffering bad lag (High Utlization)
I am running on that server Oracle10g with apache_1.3.35/ php-4.4.2
Web visitors retrieve data from the web by php calls through oci
cobnnection...
|
by: DanielJohnson |
last post by:
int main()
{
printf("\n Hello World");
main;
return 0;
}
This program terminate just after one loop while the second program
goes on infinitely untill segmentation fault (core dumped) on...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |