Hi, I have a program and i cant seem to get it to work. I need to write a program that can take up to 50 strings and then reverse them...
The actual question is:
Write a program that will prompt the user for two strings of characters(each string has maximum 50 characters) , assemble them into a single string and then print the string out reversed.
So far i have this
#include<stdio.h>
#include<iostream.h>
#include<string.h>
void Reverse(string &InputString);
void Reverse(string &InputString2);
void CharacterSwap(char First, char Second);
void main()
{
char InputString;
printf("Please enter the First string... ");
scanf("%s", &InputString);
printf("Please enter the Second string... ");
scanf("%s", &InputString2);
printf("You entered: ");
for(int i = 50; i < InputString.length(); i++)
printf("InputString[i]");
Reverse(InputString);
printf("The string reversed is : ");
for(int j = InputString.length(); j > 50 ; j--)
printf("InputString[j]");
printf("", endl endl);
}
void Reverse(string &InputString)
{
int Begin = 1,
End = InputString.length();
while(Begin < End)
{
CharSwap(InputString[Begin], InputString[End]);
Begin++;
End--;
}
}
void CharSwap(char& First, char& Second)
{
char Temp;
First = Second;
Temp = First;
Second = Temp;
}
<< moderator edit: added [code][/code] tags >>
I also have a nother source that works but i cant get the second one to work
please i need help soon:
#include <stdio.h>
#include <string.h>
int main ( ) {
char str[50];
char string[50];
int i, add, add1;
printf("Enter First string : ");
scanf("%49[^\n]%*c", str);
printf("Enter Second string : ");
scanf("%49[^\n]%*c", string);
printf("In reverse order : ");
add = strlen(str), add1 = strlen(string);
for (i = (add + add1) - 1; i >= 0; i--)
putchar(str[i], string[i]);
putchar('\n');
return 0;
}
thanxs