![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Nov 2005
Posts: 7
Rep Power: 0
![]() |
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++ ){ } |
|
|
|
|
|
#2 |
|
Professional Programmer
|
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;} |
|
|
|
|
|
#3 |
|
Newbie
Join Date: Nov 2005
Posts: 7
Rep Power: 0
![]() |
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++ ){ } |
|
|
|
|
|
#4 |
|
Professional Programmer
|
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;} |
|
|
|
|
|
#5 | |
|
Hobbyist Programmer
Join Date: Jun 2005
Location: New Mexico
Posts: 228
Rep Power: 4
![]() |
Quote:
You flipped the arguments....char *fgets(char *s, int n, FILE *stream); |
|
|
|
|
|
|
#6 | |
|
Professional Programmer
|
Quote:
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;} |
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|