I am trying to write to files called something that I give in my command-line. For example I call "a.out blahblah.c16", and then I want to create two new strings "blahblah.o" and "blahblah.syms" and then write to them. I've tried strcat, and doing it character by character, but nothing seems to work.
This is what I'm working with so far:
Code:
char * name = malloc(sizeof(strlen(argv[1])));
strncpy(name, argv[1], s1);
printf("name is '%s'\n", name);
char o[MAXWORDLEN]; //max is 20
char syms[MAXWORDLEN];
puto(o, name);
putsyms(syms, name);
printf("o is '%s'\n", o);
printf("syms is '%s'\n", syms);
input = fopen(argv[1], "r");
output = fopen(syms, "w");
output2 = fopen(o, "w");
here are the methods
Code:
int puto(char *str, char *name) {
int i = 0;
char c = *name;
char * name2 = name;
while ( ((c>=48 && c <=122) || c == 46) && c!='\0') {
str[i] = c;
name++;
c = *name;
i++;
}
str[i++] = '.';
str[i++] = 'o';
str[i] = '\0';
name = name2;
return 0;
}
int putsyms(char *str, char *name) {
int i = 0;
char c = *name;
while (c != '\0') {
str[i] = c;
name++;
c = *name;
i++;
}
str[i++] = '.';
str[i++] = 's';
str[i++] = 'y';
str[i++] = 'm';
str[i++] = 's';
str[i] = '\0';
return 0;
}
>a.out llo.small.int.c16
name is 'llo.small.int'
o is ''
syms is 'llo.small.int.syms'
FINISHED
HEX IS 8302
Segmentation fault (core dumped)
when I run it in eclipse, it writes to the files fine, but now I'm using a linux server and that doesn't work. Thanks in advance.