Does anyone know how to make it so an output for a program would print out the string in reverse/backwards? I was just curious on how to do this. Thanks!
Does anyone know how to make it so an output for a program would print out the string in reverse/backwards? I was just curious on how to do this. Thanks!
Start at the end of the string, and print out each character as you move to the beginning of the string.
Code:#include<stdio.h> #include<string.h> intmain(){ charstr[50]; char*rev; printf("Enter any string : "); scanf("%s",str); rev = strrev(str); printf("Reverse string is : %s",rev); return0;
Last edited by Salem; 02-20-2013 at 11:47 PM. Reason: restoration
Aside from the lack of whitespace in certain areas, your program breaks when certain kinds of input is received, and it depends on a function (strrev) that isn't declared in either stdio.h or string.h. I suggest learning what strings are, as well as how to manipulate them.
@return 0:
Don't delete your post like that, it ruins the purpose of this forum, for people to learn. Now Barney McGrew's post makes no sense, since the code he's referencing is gone. Also, nobody else can learn anything from this thread now. Editing a post should only be used for small changes (e.g. typos) or small additions. Please put it back if possible.
Barney's posts never make any sense anyway - unless you want to learn how to program.
The formatting is a mess because the code was not pasted at text, but instead in some pre-decorated horror from whatever IDE is being used.
This is the first line.
[ FONT=courier new][ COLOR=#7F0055][ FONT=Courier New]#include[ /FONT][ /COLOR][ COLOR=#2A00FF][ FONT=Courier New]<stdio.h>[ /FONT][ /COLOR][ FONT=Courier New][ /FONT][ /FONT]
The board's code formatter then barfs, and well you can see the result.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.