M
Mohan
Hi Guys,
I have a small problem in the following code....I am using gcc compiler
in ubuntu .
I dont know why this code is giving error...
Can u any one please figure it out....
Code:
1 #include<stdio.h>
2 # define SIZE 50
3 void myswap(char**,char**);
4 int main()
5 {
6 char s1[SIZE]="C";
7 char s2[SIZE]="C++";
8 char *temp;
9 myswap(&s1,&s2);
10 printf("\nStr1=%s",s1);
11 printf("\nStr2=%s\n",s2);
12 }
13 void myswap(char **name1,char **name2)
14 {
15 char *temp;
16 temp=*name1;
17 *name1=*name2;
18 *name2=temp;
19 }
Error Msg:
swap.c: In function âmainâ:
swap.c:9: warning: passing argument 1 of âmyswapâ from incompatible
pointer type
swap.c:9: warning: passing argument 2 of âmyswapâ from incompatible
pointer type
But the following code is worrking....Check this code also...
1 #include<stdio.h>
2 #include<stdlib.h>
3 # define SIZE 50
4 void myswap(char**,char**);
5 int main()
6 {
7 char *s1;
8 char *s2;
9 s1=(char *)malloc(SIZE);
10 s2=(char *)malloc(SIZE);
11 printf("\nEnter a string : ");
12 fgets(s1,SIZE,stdin);
13 printf("\nEnter a string : ");
14 fgets(s2,SIZE,stdin);
15 myswap(&s1,&s2);
16 printf("\nStr1=%s",s1);
17 printf("\nStr2=%s\n",s2);
18 }
19 void myswap(char **name1,char **name2)
20 {
21 char *temp;
22 temp=*name1;
23 *name1=*name2;
24 *name2=temp;
25 }
Can anyone calrify my doubt?
My question is
1.Array name is pointer to base element....So i can pass the address of
array name(which is a pointer)....The code shud work as per the logic?
But its not so?
2.The same function myswap() is working for DMA variables.
Waiiting for proper reply?
Thanks in advance.....
MOHAN S
I have a small problem in the following code....I am using gcc compiler
in ubuntu .
I dont know why this code is giving error...
Can u any one please figure it out....
Code:
1 #include<stdio.h>
2 # define SIZE 50
3 void myswap(char**,char**);
4 int main()
5 {
6 char s1[SIZE]="C";
7 char s2[SIZE]="C++";
8 char *temp;
9 myswap(&s1,&s2);
10 printf("\nStr1=%s",s1);
11 printf("\nStr2=%s\n",s2);
12 }
13 void myswap(char **name1,char **name2)
14 {
15 char *temp;
16 temp=*name1;
17 *name1=*name2;
18 *name2=temp;
19 }
Error Msg:
swap.c: In function âmainâ:
swap.c:9: warning: passing argument 1 of âmyswapâ from incompatible
pointer type
swap.c:9: warning: passing argument 2 of âmyswapâ from incompatible
pointer type
But the following code is worrking....Check this code also...
1 #include<stdio.h>
2 #include<stdlib.h>
3 # define SIZE 50
4 void myswap(char**,char**);
5 int main()
6 {
7 char *s1;
8 char *s2;
9 s1=(char *)malloc(SIZE);
10 s2=(char *)malloc(SIZE);
11 printf("\nEnter a string : ");
12 fgets(s1,SIZE,stdin);
13 printf("\nEnter a string : ");
14 fgets(s2,SIZE,stdin);
15 myswap(&s1,&s2);
16 printf("\nStr1=%s",s1);
17 printf("\nStr2=%s\n",s2);
18 }
19 void myswap(char **name1,char **name2)
20 {
21 char *temp;
22 temp=*name1;
23 *name1=*name2;
24 *name2=temp;
25 }
Can anyone calrify my doubt?
My question is
1.Array name is pointer to base element....So i can pass the address of
array name(which is a pointer)....The code shud work as per the logic?
But its not so?
2.The same function myswap() is working for DMA variables.
Waiiting for proper reply?
Thanks in advance.....
MOHAN S