Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Nov 13th, 2005, 10:44 PM   #1
monkijunki2
Newbie
 
Join Date: Nov 2005
Posts: 7
Rep Power: 0 monkijunki2 is on a distinguished road
c strings in an array problem

Hi,
How should I go about storing strings in an array without using the getc function? getc works but it's apparently not a good function to use. I tried getline, but I always get a segmentation fault when reading from the array. Thanks.

getc line of code:

int n;
char names[10][31];

for( n=0; (n<MAX) && gets(names[n]); n++ ){
}
monkijunki2 is offline   Reply With Quote
Old Nov 14th, 2005, 5:01 PM   #2
iignotus
Professional Programmer
 
iignotus's Avatar
 
Join Date: Apr 2005
Location: Nowhere Special
Posts: 466
Rep Power: 4 iignotus is on a distinguished road
Send a message via AIM to iignotus
Use fgets, lol.
fgets(stdin, 30, names[n]);
__________________
% rc4 hexkey < input > output
#define S ,t=s[i],s[i]=s[j],s[j]=t /* rc4 hexkey <file */
unsigned char k[256],s[256],i,j,t;main(c,v,e)char**v;{++v;while(++i)s[ 
i]=i;for(c=0;*(*v)++;k[c++]=e)sscanf((*v)++-1,"%2x",&e);while(j+=s[i]
+k[i%c]S,++i);for(j=0;c=~getchar();putchar(~c^s[t+=s[i]]))j+=s[++i]S;}
iignotus is offline   Reply With Quote
Old Nov 14th, 2005, 5:10 PM   #3
monkijunki2
Newbie
 
Join Date: Nov 2005
Posts: 7
Rep Power: 0 monkijunki2 is on a distinguished road
thanks iignotus !! that's what i was looking for !! =P can you tell i'm a little newbie? heeh

new code:
int n;
char names[10][31];

for( n=0; (n<MAX) && fgets(names[n], 31, stdin); n++ ){
}
monkijunki2 is offline   Reply With Quote
Old Nov 14th, 2005, 5:18 PM   #4
iignotus
Professional Programmer
 
iignotus's Avatar
 
Join Date: Apr 2005
Location: Nowhere Special
Posts: 466
Rep Power: 4 iignotus is on a distinguished road
Send a message via AIM to iignotus
Use code tags.
__________________
% rc4 hexkey < input > output
#define S ,t=s[i],s[i]=s[j],s[j]=t /* rc4 hexkey <file */
unsigned char k[256],s[256],i,j,t;main(c,v,e)char**v;{++v;while(++i)s[ 
i]=i;for(c=0;*(*v)++;k[c++]=e)sscanf((*v)++-1,"%2x",&e);while(j+=s[i]
+k[i%c]S,++i);for(j=0;c=~getchar();putchar(~c^s[t+=s[i]]))j+=s[++i]S;}
iignotus is offline   Reply With Quote
Old Nov 14th, 2005, 5:50 PM   #5
jim mcnamara
Hobbyist Programmer
 
Join Date: Jun 2005
Location: New Mexico
Posts: 228
Rep Power: 4 jim mcnamara is on a distinguished road
Quote:
Originally Posted by iignotus
Use fgets, lol.
fgets(stdin, 30, names[n]);
Use examples that are correct You flipped the arguments....

 char *fgets(char *s, int n, FILE *stream);
jim mcnamara is offline   Reply With Quote
Old Nov 14th, 2005, 11:15 PM   #6
iignotus
Professional Programmer
 
iignotus's Avatar
 
Join Date: Apr 2005
Location: Nowhere Special
Posts: 466
Rep Power: 4 iignotus is on a distinguished road
Send a message via AIM to iignotus
Quote:
Originally Posted by jim mcnamara
Use examples that are correct You flipped the arguments....

 char *fgets(char *s, int n, FILE *stream);
I didn't , I just copied it.
__________________
% rc4 hexkey < input > output
#define S ,t=s[i],s[i]=s[j],s[j]=t /* rc4 hexkey <file */
unsigned char k[256],s[256],i,j,t;main(c,v,e)char**v;{++v;while(++i)s[ 
i]=i;for(c=0;*(*v)++;k[c++]=e)sscanf((*v)++-1,"%2x",&e);while(j+=s[i]
+k[i%c]S,++i);for(j=0;c=~getchar();putchar(~c^s[t+=s[i]]))j+=s[++i]S;}
iignotus is offline   Reply With Quote
Old Nov 15th, 2005, 11:42 AM   #7
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
Yeah, from me. I got it wrong. :p
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 4:46 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC