A
Albert
This not-yet-working C program's aim is to output each input line
reversed (so if the user enters 'hello', the program will output
'olleh' - and please assume this stdout and stdin!!!).
Why the h**l isn't this WORKING AND WHY DOES IT CRASH???!
#include <stdio.h>
#define MAXINPUT 256
void reverse(char[], int);
main()
{
int c;
int number;
char s[MAXINPUT];
int i;
for (i=0; (i<MAXINPUT-1) && ((c = getchar()) != '\n'); i++) {
s = c;
++number;
}
reverse(s, number);
for (i=0; i<=number; i++)
putchar(s);
return 0;
}
void reverse(char s[], int num_elements)
{
int i, j;
for (i=0,j=num_elements-1; (i<=num_elements-1) && (j>=0); i++,j--)
s = s[j];
}
reversed (so if the user enters 'hello', the program will output
'olleh' - and please assume this stdout and stdin!!!).
Why the h**l isn't this WORKING AND WHY DOES IT CRASH???!
#include <stdio.h>
#define MAXINPUT 256
void reverse(char[], int);
main()
{
int c;
int number;
char s[MAXINPUT];
int i;
for (i=0; (i<MAXINPUT-1) && ((c = getchar()) != '\n'); i++) {
s = c;
++number;
}
reverse(s, number);
for (i=0; i<=number; i++)
putchar(s);
return 0;
}
void reverse(char s[], int num_elements)
{
int i, j;
for (i=0,j=num_elements-1; (i<=num_elements-1) && (j>=0); i++,j--)
s = s[j];
}