Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //working
- main()
- {
- int c;
- int i = 0;
- char array[MAXARRAYSIZE];
- while ((c = getchar()) != '!')
- array[i++] = c;
- array[i] = '\0';
- reverse(array);
- printf("%s", array);
- }
- void reverse(char s[])
- {
- char temp[MAXARRAYSIZE];
- int i = 0;
- int j = 0;
- int pointofreverse = 0;
- while (s[i] != '\0' && s[i] != EOF)
- {
- while (s[i] != '\n' && s[i] != '\0' && s[i] != EOF)
- i++;
- pointofreverse = i - 1;
- while (j < i)
- temp[j++] = s[pointofreverse--];
- temp[j++] = s[i];
- if (s[i] != '\0')
- i++;
- }
- temp[j] = '\0';
- i = 0;
- while ((s[i] = temp[i]) != '\0')
- i++;
- }
- //not working
- main()
- {
- int c;
- int i = 0;
- char array[MAXARRAYSIZE];
- while ((c = getchar()) != '!')
- array[i++] = c;
- array[i] = '\0';
- reverse(array);
- printf("%s", array);
- }
- void reverse(char s[])
- {
- char temp[MAXARRAYSIZE];
- int i = 0;
- int j = 0;
- int pointofreverse = 0;
- while (s[i] != '\0' && s[i] != EOF)
- {
- while (s[i] != '\n' && s[i] != '\0' && s[i] != EOF)
- i++;
- pointofreverse = i - 1;
- while (j < i)
- temp[j++] = s[pointofreverse--];
- temp[j++] = s[i++]; //only difference
- }
- temp[j] = '\0';
- i = 0;
- while ((s[i] = temp[i]) != '\0')
- i++;
- }
Advertisement
Add Comment
Please, Sign In to add comment