LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-10-2005, 06:56 AM   #31
exvor
Senior Member
 
Registered: Jul 2004
Location: Phoenix, Arizona
Distribution: Gentoo, LFS, Debian,Ubuntu
Posts: 1,537

Rep: Reputation: 87

maybe something like this

Code:
 


// asumeing FILE is text 

   do {
    
     printf("%c",fgetc(text)); 
      
     } 
   while (fgetc(text) != 'EOF');
 
Old 09-10-2005, 09:03 AM   #32
Goblin_C_Noob
Member
 
Registered: Sep 2005
Posts: 48

Rep: Reputation: 15
nah thats fixed, WAY past that.

im now at the point were im trying to read in a string from the kb and send it to a function.

Code:
char*compare=(char*)malloc(sizeof(char*)*20);
scanf("%s",compare);
ReadCatalogue(myfile,*choice,compare);

//ReadCatalogue takes in:

void ReadCatalogue(FILE *myfile, int choose, char*compare)
this is were it starts laughing at me .

why? And what can i do to fix it?

Last edited by Goblin_C_Noob; 09-10-2005 at 09:08 AM.
 
Old 09-10-2005, 07:15 PM   #33
Goblin_C_Noob
Member
 
Registered: Sep 2005
Posts: 48

Rep: Reputation: 15
ok, heres the deal:


Code:
myfile=fopen("getlin.txt","r+");
char*compare=(char*)malloc(sizeof(char*)*20);
int*choice=(int*)malloc(sizeof(int*)*2);
scanf("%d",choice);
printf("\nWhat would you like to search for?");
scanf("%s",compare);
printf("%s\n",compare);
ReadCatalogue(myfile,*choice,*compare);    /*Call to function, ReadCatalogue, (this is were it segments)*/



void ReadCatalogue(FILE *myfile, int choose, char**compare)     /*The called function, ReadCatalogue*/

is anyone able to suggest a reason for this?

i know it has something to do with my arguments when calling ReadCatalogue cause i get this warning when compiling

warning: passing arg 3 of `ReadCatalogue' makes pointer from integer without a cast.

this wasnt covered in the lecture notes and i havent a clue what it means.

Last edited by Goblin_C_Noob; 09-10-2005 at 07:16 PM.
 
Old 09-11-2005, 05:50 AM   #34
Lux Perpetua
LQ Newbie
 
Registered: Aug 2005
Location: Local Group
Distribution: Ubuntu Linux
Posts: 15

Rep: Reputation: 0
compare is a char *, so *compare is a char. ReadCatalogue is expecting a char **, not a char.
 
Old 09-11-2005, 08:09 AM   #35
Goblin_C_Noob
Member
 
Registered: Sep 2005
Posts: 48

Rep: Reputation: 15
hehe, you guys must be really getting tired of my noobishness.

Code:
char *Catalogue = malloc(sizeof(*Catalogue)*10);
Catalogue = "a";
printf("What file would you like to load? ");
scanf("%9s",Catalogue);
ReadCatalogue(myfile);

segments here

this is really starting to piss me off too, so im sorry for all those that read my code and start rocking in your chairs because of how bad it looks, but i dont do it on purpose.

i also get the same problem here:

Code:
char *Catalogue = malloc(sizeof(*Catalogue)*10);
Catalogue = "a";
myfile=fopen(Catalogue,"r+");
int*choice = malloc(sizeof(*choice)*2);
choice = 0;
scanf("%1d",choice);

Last edited by Goblin_C_Noob; 09-11-2005 at 08:13 AM.
 
Old 09-11-2005, 09:48 AM   #36
Goblin_C_Noob
Member
 
Registered: Sep 2005
Posts: 48

Rep: Reputation: 15
never mind, thanx guys i fixed it, but only with your expert help.
 
Old 09-11-2005, 10:48 AM   #37
Goblin_C_Noob
Member
 
Registered: Sep 2005
Posts: 48

Rep: Reputation: 15
hey, just me again:

new segfault and this one aint my fault

Code:
char *temp = malloc(sizeof(*temp)*10);
temp[0]='a';
scanf("%9s",temp);
thats it, it segfaults at scanf and i dont know why.
 
Old 12-16-2007, 09:09 AM   #38
Zayar Win
LQ Newbie
 
Registered: Dec 2005
Location: Myanmar, Russian Federation
Distribution: RedHat 9, RHEL AS, Dyne:bolic, Open SUSE 10.3
Posts: 18

Rep: Reputation: 0
Yeah, you fixed my problem!!! Thanks!!!
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
what does Segmentation Fault mean ? baronlynx Linux - Newbie 10 10-25-2009 04:32 PM
yast segmentation fault, system freezing - nvidia driver at fault? BaltikaTroika SUSE / openSUSE 2 12-02-2005 09:34 AM
Help !!! Segmentation fault mola Linux - Software 3 06-23-2005 11:13 AM
Segmentation fault tejas15_10 Programming 9 06-20-2005 09:12 AM
Segmentation fault santhosh_o Programming 3 10-26-2004 05:45 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:54 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration