0 like 0 dislike
3.3k views

In the following program, we want to stores two strings in two arrays, swaps them, and displays their new content. There some error. Please fix it and explain why and how in the comment after your answer.

#include <stdio.h>
int main(){
    char temp[100];
    char str1[100] = "Let see";
    char str2[100] = "Is everything OK?";
    temp = str1;
    str1 = str2;
    str2 = temp;
    printf("%s %s", str1, str2);
    return 0;
}

 

[Exercise] Coding (C) - asked in Chapter 11: Pointers
ID: 38255 - Available when: Unlimited - Due to: Unlimited
1 flag | 3.3k views

30 Answers

0 like 0 dislike
Hidden content!
#include * * * *
** * * *** **
void change(int *str1,int *str2);

int main(){
** * * * ** ******* * * temp[100];
****** ** * * * ** ** str1[100] = * * * * *
*** ** **** ** *** * ** * ** * str2[100] = * **** everything ** **


* * * ** * * * * ******** = str1;
** *** ** ** ** * *** ** = str2;
**** ** ** * *** ** ***** * = temp;
* **** * ** *** * * * * * * * * *
* * *** *** * * ** * * * *
* ** * * *** * * **** *
* *** * * ** **** ** * * * ** ** *** str1, str2);
* ***** *** * * *** * ***** 0;
}
answered by (-32 points)
0 0
Case 0: Correct output
0 like 0 dislike
Hidden content!
#include *** ** * *****
int main(){
* ** * * * ****** * ******* **
* *** * * *** **** ** ** *str1[100] = * *** * *******
**** *** * ** *** * *str2[100] = ** * *** everything * * *
* ** * *** *** * * * = *str1;
** ** * *** ** * ** * = *str2;
* **** *** ****** *** *** * * * = *temp;
**** *** ******* ***** ** **** * * * ****** *str1, *str2);
** * * * **** * *** * *** 0;
}
answered by (-193 points)
0 0
Case 0: Correct output
0 like 0 dislike
Hidden content!
#include * *** **** ** *******
int main()
{
* ******** *** ** * * * temp[100];
* *** * ** ** * * * str1[100] = "Let * * * **
* * ** *** *** * str2[100] = "Is everything ** * ***
*** * * * ** *** *** * * * *
*** ****** * ******** ** ***** = * ** *
* * * *** * * **** ** ** = ** **
** * ****** * ** ** * * *** = ** * * * * **
*** ** *** **** * * **** = *p2;
* ********* * **** **** = *p3;
* * * * ** ** *** ** ** = *p1;
* * * *** *** ** ** * ** * *** %s", str1, str2);
** **** * ****** *** 0;
}
answered by (-214 points)
0 0
Case 0: Wrong output
0 like 0 dislike
Hidden content!
*** ** * * ** * * ** *
int ***
{
** ** * * **
** * char **
* * ***** * char * = ***** * * **
** ** * * * * * char *** = ** ***** ***
* **** * temp = str1;
* ** ** ** str1 = *
* * * * *** str2 = temp;

*** * ** /*
* * * ** char * * *
* * char ** = * * * *** * *
** ** * char ** = *** ** * * * ** ** * *
* * * *** ** **** i = 0; i * ** 100; i++)
* * ** * {
* **** * * ** * * *** **** ** = * * *
***** * ** * * * * * * * *** * = * ***
*** * * * * ** *** ****** ** * = ***
** * ** * ** }
** * **** */
* *** * * * * ** * * ** * * * **
* * * ** * ** ** 0;
}
answered by (-285 points)
0 0
Case 0: Correct output
0 like 0 dislike
Hidden content!
#include * *** ****
int main(){
** ***** * ** ** ** * *** *temp;
* * * * * * ** *** * *str1 = ** **** * * *
* * **** * * * * * *str2 = * * everything **** * ****
* ** * * ******* * * = str1;
** ** ** * *** **** **** ** * = str2;
** ** ***** ** * ** * = temp;
* * * * ***** * * * * **** * * ** str1, str2);
* * * ** ** * * ** * 0;
}
answered by (-16 points)
0 0
Case 0: Correct output
0 0
Case 0: Correct output
0 0
原型態為指標常數,其值不可更改;指標變數的值才能被更改
0 like 0 dislike
Hidden content!
#include * * * * * *** *
int main()
{
** * ** * **** i;
** *   char * **
* * ***** * **** * * * ** str1[100] = * *** * * ** * * *
* * ** * * * * *** * ** str2[100] = * everything ****
* ** * ** ** ** ** * * * **
* * * *** * ***** ***
* ***** ** *** *** ******* * * temp[i] = str1[i];
***** ** * * * ** * * * str1[i] = str2[i];
* *** * *** *** ***** ***** ** * * str2[i] = **** * *
** * * *** }
* * * ***
* * ** * *** * ***** * ** * * str1, str2);
** **** ** *** ** * * * * 0;
}
answered by (-249 points)
0 0
Case 0: Correct output
0 like 0 dislike
Hidden content!
* ** ** * *****
int ** *
* **** ** * ***** * * *** *
*** * * * * *** ** *** * * ** ** ** = ** ** * * ** *
** * * **** ** * *str2 = *** * **** * *
* * ***** **** *** * ***** = ***
******** * * * * * * * * = str2;
** * *** ** ** * * = **
* *** ** *** ** * ** ** * * ** str1, ****
** * ** * ** **** * 0;

}
/* A name of * * ** ** must be * by an * Here in *** * code there was no * in front of ***** ** * name */
answered by (-304 points)
edited by
0 0
Case 0: Wrong output
0 0
Case 0: Wrong output
0 0
Case 0: Correct output
0 like 0 dislike
Hidden content!
* * * *** ** ****


int * *
* **** *** ** * * * *
* * * ** * **** ** *** *str1 = * * ** ** * *
* * * * ** * * **** ** *str2 = * * * * * **** ***
** * * ** ** ** ** * ******* = str1;
* **** ****** ** * * = str2;
* ****** ** *** ** * * ** = temp;
** * * * * * * ** * ** * *** str1,
** *** * * * * *** * **
* ** * ** * ** * ******* 0;
}

/*
**** char **** and * *** * *** ** into this array may * * * due to white *
* * we can * * as char ********* ****
*/
answered by (-74 points)
0 0
Case 0: Correct output
0 like 0 dislike
Hidden content!
#include * * *** ** * *
* **** *** * *** * *
void change(int *str1,int *str2);

int main(){
* *** ** ** * * * ** *
* **** * * *** **** * *** str1[100] = * * ** ******
*** ******** * ** *** str2[100] = * ** everything *****
*** *** *** **** * *** *
* * * * ************ * **** ** *
**** ** * * *** ** ** ** * ** *
********* * * * * * * *** *** * ** * * str1, str2);
* * ** ** *** * **** ** 0;
}
answered by (-140 points)
edited by
0 0
prog.c:1:1: error: unknown type name 'assignment'
 assignment to expression with array type
 ^~~~~~~~~~
prog.c:1:15: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'expression'
 assignment to expression with array type
               ^~~~~~~~~~
prog.c:1:15: error: unknown type name 'expression'
0 0
Case 0: Wrong output
0 0
Case 0: Correct output
0 like 0 dislike
Hidden content!
#include * * *** **
int main(){
*** * * * *** * ******** *** *temp;
* * * ****** * * * ** * * *str1 = * **** * **
* * *** * **** * * *str2 = ** * **** everything * ***
* * * * * ** * * ****** * = str1;
* * ** ** **** * * *** = str2;
*** ** ** *** ** ******* ** * = temp;
*** ** * **** *** * *** ***** * * * ** *** *** ***** str1, str2);
** * *** * ** *** * ** ***** 0;
}
answered by (-254 points)
0 0
Case 0: Correct output
Welcome to Peer-Interaction Programming Learning System (PIPLS) LTLab, National DongHwa University
English 中文 Tiếng Việt
IP:172.69.58.213
©2016-2024

Related questions

1 like 0 dislike
75 answers
[Exercise] Coding (C) - asked Oct 12, 2017 in Chapter 3: Formatted Input/Output by thopd (12.1k points)
ID: 26464 - Available when: Unlimited - Due to: Unlimited
| 5.7k views
3 like 0 dislike
87 answers
[Exercise] Coding (C) - asked Oct 12, 2017 in Chapter 3: Formatted Input/Output by thopd (12.1k points)
ID: 26463 - Available when: Unlimited - Due to: Unlimited
| 6.4k views
12,783 questions
183,443 answers
172,219 comments
4,824 users