Change place characters - C

1

I need to write a program in C that takes a string as a parameter and generates a new string consisting of the original string with the following changes:

  

● The first character of the string must be placed at the end of the string;

     

● The suffix "ay" must be added to the end of this string. Consider that   the string received by the program will be 100 characters maximum. Not   to use any library function <string.h>

But I'm having a hard time switching places.

Code:

#include <stdlib.h>
#include <stdio.h>

int main(int argc, char** argv){

    char string[101];
    char letra[2];
    char comp[3]="ay";
    int count, i;

    printf("String:  ");
    scanf("%s", string);

    for(count=1; string[i]!='
#include <stdlib.h>
#include <stdio.h>

int main(int argc, char** argv){

    char string[101];
    char letra[2];
    char comp[3]="ay";
    int count, i;

    printf("String:  ");
    scanf("%s", string);

    for(count=1; string[i]!='%pre%'; i++){
        count++;
    }
}
'; i++){ count++; } }
    
asked by anonymous 08.08.2016 / 18:39

1 answer

1

I believe this code will solve the problem ...

#include <stdlib.h>
#include <stdio.h>

int main(int argc, char** argv){

    char string[101];
    char letra[2];
    char comp[3]="ay";
    int count, i;

    printf("String:  ");
    scanf("%s", string);

    for(count=0; string!='
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

int main()

{

    char string[101], backup;

    int tamanho_str;

    printf("String:  ");
    scanf("%s", string);

    tamanho_str = strlen (string);

    backup = string[tamanho_str-1];

    string [tamanho_str-1] = string [0];

    string [0] = backup;

    strcat (string, "ay");

    printf ("\nstring final: %s\n", string);

    return 0;
}
'; i++){ count++; } letra[0]=string[0]; string[0]=string[count]; string[count]=letra[0]; string[count+1]='a'; string[count+2]='y'; printf("%s",string); }

If you could use <string.h> it would be easier:

#include <stdlib.h>
#include <stdio.h>

int main(int argc, char** argv){

    char string[101];
    char letra[2];
    char comp[3]="ay";
    int count, i;

    printf("String:  ");
    scanf("%s", string);

    for(count=0; string!='
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

int main()

{

    char string[101], backup;

    int tamanho_str;

    printf("String:  ");
    scanf("%s", string);

    tamanho_str = strlen (string);

    backup = string[tamanho_str-1];

    string [tamanho_str-1] = string [0];

    string [0] = backup;

    strcat (string, "ay");

    printf ("\nstring final: %s\n", string);

    return 0;
}
'; i++){ count++; } letra[0]=string[0]; string[0]=string[count]; string[count]=letra[0]; string[count+1]='a'; string[count+2]='y'; printf("%s",string); }
    
08.08.2016 / 18:46