[Solved] Incomplete type is not allowed in swap program


The below program does what you want:

#include<stdio.h>
#include<conio.h>
#include<string.h>
void swapping(char s1[],char s2[])
{
char temp[30]; //create an array of char in order to store a string

strcpy(temp,s1);
strcpy(s1,s2);
strcpy(s2,temp); //use strcpy to swap strings
}

int main (void)
{
char st1[30],st2[30];

printf("Enter the first string");
scanf("%s",st1);
printf("Enter the second string");
scanf("%s",st2); //the & is removed from both the scanfs

printf("The first string is %s and the second string is %s \n",st1,st2); //print before swapping 
swapping(st1,st2); //swap strings

printf("The first string is %s and the second string is %s \n",st1,st2); //print after swapping

getch();
return 0;
}

You can remove the printf which prints st1 and st2 before swapping if you do not want it. The & is removed because the name of the array decays to a point er to its first element. You also need another char array instead of an int to swap both the strings.

solved Incomplete type is not allowed in swap program