Alright, here's what I'm working on now. It's supposed to go through an inputted list of words, pick out actual words and create a numbered list of them, then, where it finds a number in the list, go back in the list from that number, replace it with a word, augment the list accordingly and continue.
Anyways, here's what I have:
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
int main ()
{
char line[100];
char word[100];
char tword[20];
int k = 0, index = 0, nwords = 0, j;
gets(line);
while(line[0] != '0')
{
if(isalpha(line[k]))
{
j = 0;
while (isalpha(line[k]))
{
tword[j] = line[k];
j++;
k++;
}
tword[j] = '\0';
strcpy(word[nwords], tword);
nwords++;
}
else if(isdigit(line[k]))
{
index = atoi(line[k]);
k++;
if(isdigit(line[k]))
{
index = index * 10 + atoi(line[k]);
k++;
}
printf("%s", word[nwords - index]);
strcpy(tword, word[nwords-index]);
for(j = index + 1; j < nwords; j++)
{
strcpy(word[j - 1], word[j]);
}
strcpy(word[nwords - 1], tword);
}
else
{
printf("%c", line[k]);
k++;
}
gets(line);
}
return 0;
}
The problem is that I get segmentation faults when executing. Anybody see what I'm missing?