dimanche 13 septembre 2020

how can i copy string to another variable and output with if else statement

    #include<stdio.h> 
    #include<string.h>

    int main(void) 

    {    

        //Assigning string to name1//
        char name1[8] = "Aaeric";

        //will be used to copy name1 to copyname//
        char copyname[8];  

        //Assigning string to name2//
        char name2[7] = "Mudus";

         //prompt for input//
             int i;
                 printf("Choose 1 or 0: ");
                     scanf("%i \n", &i);

    }



    //for copying string of name1 to copyname//
        if (i = 0)
        {
            strcpy(copyname, name1);
            puts(copyname);
            return 0; 
        }
        else
            puts(name2);
     }

I want to copy the string to another variable and output with if-else condition through this way only but I am getting error.

The output is the expected identifier or ‘(’ before ‘if’

Aucun commentaire:

Enregistrer un commentaire