C/switching person's name continues?!
Expert: Narendra - 7/6/2006
Questionsorry for not being so clear but also i have to use pointers so that i have used this kind of code
lot of thanks
-------------------------
Followup To
Question -
well the thing is i ain't allowed to use malloc .. as u have explained it to me
the thing is i have this code but i don't know where's the problem thanks
main()
{
char name[25];
char temp[25];
char *ptr;
int temp1;
char b;
printf("please enter name ");
gets(name);
ptr=strlen(name);
*ptr='\0';
*ptr++;
strcpy(temp,ptr);
strcat(temp,",");
strcat(temp,name);
puts(name);
}
Answer -
Here is the corrected code:
#include <stdio.h>
main()
{
char name1[25], name2[25];
char temp[25];
printf("please enter name1 => ");
gets(name1);
printf("please enter name2 => ");
gets(name2);
printf("Before swap:\n");
printf("Name1 => %s\n", name1);
printf("Name2 => %s\n", name2);
strcpy(temp, name1);
strcpy(name1,name2);
strcpy(name2, temp);
printf("After swap:\n");
printf("Name1 => %s\n", name1);
printf("Name2 => %s\n", name2);
}
AnswerSo, what is the complete problem statement?
You must use pointers and you should not use malloc!?
Is that right?
And are you allowed to use, any number of temporary variables?
If you make your problem statement clear, we can try to get the correct solution.