My program takes in the Constitution, reverses the line order, and prints the Constitution in reverse order back in the command line. When I put the algorithm to reverse the lines in a separate function, lineReversal, the only thing that prints is ▒▒▒.
int main(){
char * buffer;
char * strings[1000];
int arrayCount =0;
int size = 10;
while(!feof(stdin))
{
buffer= (char*) malloc(size);
getAline(&buffer, &size); //gets each line from the Constitution
strings[arrayCount++] = buffer;
}
lineReversal(&strings);
return 0;
}
char lineReversal(char ** stringPtr)
{
char * strings = *stringPtr;
for(int i = 873; i >=0 ; i--) {
if(strings[i] == '\0'){
break;
}
printf("%s", strings + i);
}
*stringPtr = strings;
return 0;
}
If I put that algorithm into main() and run my program, this is my output:
H▒▒▒▒▒▒▒▒▒▒▒▒Dhave intervened.Representatives, shall take effect, until an election of Representatives shall
The expected output is:
have intervened.
This is what my program looks like with the algorithm inside main.
int main(int argc, char ** argv){
char * buffer;
char * strings[1000];
int arrayCount =0;
int size = 10;
while(!feof(stdin))
{
buffer= (char*) malloc(size);
getAline(&buffer, &size);
strings[arrayCount++] = buffer;
}
for(int i = 873; i >=0 ; i--)
{
if(strings[i] == '\0'){
break;
}
printf("%s", strings[i]);
}
return 0;
}