Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #define STR_LEN 80
- char str[STR_LEN+1];
- void reverse();
- int main (){
- printf ("Enter a sentence: \n");
- fgets(str,STR_LEN+1,stdin);
- puts( str );
- reverse();
- return 0;
- }
- void reverse(){
- char newstr[STR_LEN+1];
- char thirdar[STR_LEN+1];
- char fourar[STR_LEN+1];
- char temp[STR_LEN+1];
- char output[STR_LEN+1];
- char symbol [STR_LEN+1];
- int c = 0;
- int i;
- char ch1;
- char ch2;
- char ch3;
- for(i=0; i<STR_LEN; i++){
- ch1 = str[i];
- newstr[c] = ch1;
- c++;
- }
- puts( newstr);
- int a = strlen(newstr);
- a = a - 1;
- c=0;
- for(i=a;i>-1; i--){
- ch2 = newstr[i];
- thirdar[c] = ch2;
- c++;
- }
- puts( thirdar );
- int b = strlen(thirdar);
- b=b - 1;
- for(i=b;i>-1;i--){
- while(c < b+1){
- ch3 = thirdar[i];
- if ((ch3 != ' ') ||(ch3 != '?')||(ch3 != '!')||(ch3 != '.')){
- fourar[c] = ch3;
- fourar[c+1] = '\0';
- strcpy(temp, fourar);
- c--;
- c++;
- }
- else if(ch3 == ' '){
- fourar[c] = ch3;
- fourar[c+1] = '\0';
- strcpy(temp, fourar);
- c--;
- c++;
- }
- else if((ch3 != '?')||(ch3 != '!')||(ch3 != '.')){
- fourar[c] = ch3;
- fourar[c+1] = '\0';
- strcpy(symbol, fourar);
- c--;
- c++;
- }
- }
- }
- int d = strlen(temp);
- int e = strlen(fourar);
- if(e == d){
- strcat(symbol, fourar);
- strcpy(output, symbol);
- }
- else{
- strcat(symbol,fourar);
- strcat(symbol, temp);
- strcpy(output, symbol);
- }
- puts( output);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement