WoodSTokk, thank you for the reply.
I am not sure how to cut the line into sequences. Can you explain a little more.
Can you explain the center and right align a little more as well.
Here is what I have now with the additions of your suggestions.
Code:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#define MAXC 256
int main(int argc, char *argv[]) {
int wordslength;
sscanf(argv[2], "%*[^0123456789]%d", &wordslength);
FILE *fname;
char str[MAXC];
int i;
int x;
int y;
int z;
char **words = NULL;
char buf[wordslength + 1];
int *n;
int nwords = 0;
int maxlen = MAXC > 0 ? MAXC : 1;
int rows;
//sscanf(argv[2], "%*[^0123456789]%d", &wordslength);
//printf("%d\n", wordslength);
//printf("%c\n", buf);
file = fopen(argv[1], "r");
if((fname = fopen(argv[1], "r")) == NULL) {
fprintf(stderr, "could not open file '%s'! exit.\n", argv[1]);
exit(1);
}
while(fgets(str, wordslength + 1, file)) {
//y = strlen(str);
//y = strlen(buf);
/*if(buf[y - 1] == '\n')
buf[--y] = 0;
words[(*n)++] = strdup (buf);*/
/*if (*n == maxlen) { //realloc as required, update maxlen
void *tmp = realloc (words, maxlen * 2 * sizeof *words);
words = tmp;
memset (words + maxlen, 0, maxlen * sizeof *words);
maxlen *= 2;
}*/
for(x = wordslength; x >= 0; x--) {
printf("%c", str[x]);
}
printf("\n");
}
/*if(!(words = calloc(maxlen, sizeof*words))) {
fprintf(stderr, "getwords() error: virtual memory exhausted.\n");
return NULL;
}*/
/*while(fgets(buf, wordslength + 1, file)) {
size_t wordlen = strlen(buf);
if(buf[wordlen - 1] == '\n') {
buf[--wordlen] = 0;
if(*n == maxlen) {
void *tmp = realloc(words, maxlen* 2* sizeof *words);
//if(!tmp) {
//fprintf(stderr "getwords() realloc: memory exhausted.\n");
//return words;
//}
words = tmp;
memset(words + maxlen, 0, maxlen* sizeof *words);
maxlen*=2;
}
}
//return words;
//fclose(file);
printf("\n '%d' lines read from '%s'\n\n", nwords, file);
for(i=0; i < nwords; i++) {
printf("%s\n", words[i]);
}
//fclose(file);
//return 0;
}*/
fclose(file);
return 0;
}
The for loop is actually returning the code reversed but still not correctly. I think it goes back to the sequence thing you spoke about.
The commented out code is stuff I am playing with but can't get to work correctly.