0 like 0 dislike
8.8k views

Write a program that reads strings of up to 1000 characters continuously and displays them, after replacing the lower letters with upper letters and vice versa.

寫一個程式 輸入一個字串(最多1000)  把小寫轉大寫大寫轉小寫

Example input:

With the rise in GLOBAL warming and increasing POLLUTION levels, it is becoming essential to find a viable alternative to the internal combustion engine petrol powered CAR.

Example output:

wITH THE RISE IN global WARMING AND INCREASING pollution LEVELS, IT IS BECOMING ESSENTIAL TO FIND A VIABLE ALTERNATIVE TO THE INTERNAL COMBUSTION ENGINE PETROL POWERED car.
[Exercise] Coding (C) - asked in Chapter 13: Strings
ID: 41431 - Available when: Unlimited - Due to: Unlimited

edited by | 8.8k views

57 Answers

0 like 0 dislike
Hidden content!
#include "stdio.h"

int main()

{

* * ** * ** * ** * * * * ch[1000]={0};

* * ** * * ** ** * * ** * ** * ** * i;

* *** * ** * **** * ** * *** *** *** * ** *

** * * * ** **** * ***** **** *** * *** * &ch);

* ***** **** *** ** ** * ** ** * * * * *

**** * * * *** * *** * * ** * *** * ***** ** * && ch[i]<='z')

** **** ** * * ********** * * *** * ** ** ** *** **** ** *** *** ** *

* ** * * * *** * * ** * **** **** ** * if(ch[i]>='A' && ch[i]<='Z')

** **** *** * ** ** *** **** * ** * * * * *** ** ** ** ** ** **** * *** * * * *

*** * * ******* * * ** * *** **** * ***** ****** **

** ** * * * ***** *** * * * *



}
answered by (-284 points)
0 0
prog.c: In function 'main':
prog.c:11:14: warning: zero-length gnu_printf format string [-Wformat-zero-length]
       printf("");
              ^~
prog.c:13:15: warning: format '%[^
   ' expects argument of type 'char *', but argument 2 has type 'char (*)[1000]' [-Wformat=]
     scanf("%[^\n]", &ch);
               ^
0 like 0 dislike
Hidden content!
#include <stdio.h>
#include <string.h>
int read_line(char str[], int n)
{
int ch, i = 0;
while ((ch = getchar()) != '\n')
if (i < n)
str[i++] = ch;
str[i] = '\0'; /* terminates string */
return i;
}
int write_line(char str[])
{
** ****** ** * * * i=0;
* ** ** * ****** ** * * * * * ** *
* * ****** * * ** ** **** *** * ** * * ** * * * * * ***** * * * ** **


* * ** * ** * * * ** **** **** ** * * ***
**** ** * * ** * i;
}
int main()
{
* * *** * *** * * str[1000];
** *** * * *** ****** ** i;
* * * ** ** * ***** * *
***** * * * ** ** ******** ** *** * * * ***
    {
* ** *** ** * ** ******* * *** * ** **** * ******* ** * ** ** *** *
* ** ** ***** ** * ** ** * ** * * ******
* ** * * ** * * * * ** ** ** * * * ** *** * ***** ****** **** * * *
* * *** * ** **** ******** * * *** ** *
** * * ***** * *** * * * **** *** ** ** * * * if * * * * * * ** *** *
**** **** ** * * ** * * * * * * *** ** *
*** * * * * * ** * * ** ** * * *** *** ** *** * ** * * * * * * *
** **** *** ** * ** * ******* * * * * **
* * * * * * * **
**** * * * ** **** * * * * *

* ** * ** *** * * 0;
}
answered by (-196 points)
0 0
Case 0: Wrong output
Case 1: Wrong output
Case 2: Wrong output
0 like 0 dislike
Hidden content!
#include<stdio.h>
#include<string.h>
int main()
{

*** ****** *** * i;
** *** * *** ****** ** * str1[1000],str2[1000]={0};
**** *** ** * * * *** *** **** ** ** a sentence to convert upper to lower and vice versa\n");
*** * * **** * * ** * ** * * *
*** * ** * ** *** * * *

* * ***** ** * ** * * * ******* **
******* * *** ** * *** ***
* * ** *** ** * ** *** *** * * * ******* * *** ** ** &&str1[i]<='z')
* ** ** * * * * * ***** **** * * ** ****
*** *** * **** *** * *** * *** * ** * *** ** *** * ** * **** * ** * * * ** ** **
* * *** * * ** **** * ** * * * ** **** ** **
*** ****** * * ** ***** ** ** * * * * * * * *** * ** ** *** * * * ** *
** ** ** * * **** ** ** * ** *** ** ****** * * * *** * *** * ** ** ********
* ** * * * **** **
* * * **** * *** * * *
* ** ***** *** ** * * ***** * *** ***** ** ****
***** * ** ***
}
printf("%s",str2);
return 0;
}
answered by (-167 points)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
0 like 0 dislike
Hidden content!
#include<stdio.h>
#include<stdlib.h>
* ********* *
int main()
{
*** * *** * ****** S[5000];
* * *** * * ** * * ** * ** ** 5000, stdin);

* * ** ** * * ** *** a,N=strlen(S); *** ** * *** * * *
* * * ** * * *** * ** * *** *** *
**** * * * * ** ** * * ** ** * *** * * * ***** ** && S[a]<='z' )  //大小寫轉換
** *** *** ** ** ******* * * * * ** * * ** * **** **** **** * * * * *** * **** ** * *
***** * ** ****** * ** * * * ** ** * * * * if ** * * * * ** S[a]<='Z')
** * * * ** * * * * ** * * ** ***** ** *** * * * *** * * ** * * *** * *
*** * **** * ** * * ** * *** **** **
* * * ** ***** ** * ** * * * * ** *** *** *** ** ** *** * * **** ***** * * *** * *

 return 0;
}
answered by (-127 points)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
0 like 0 dislike
Hidden content!
#include <stdio.h>
#include <string.h>
int read_line(char str[], int n)
{
int ch, i = 0;
while ((ch = getchar()) != '\n')
if (i < n)
str[i++] = ch;
str[i] = '\0'; /* terminates string */
return i;
}
int main()
{
* * * * * * ******* ** * **** str[1000];
* ** * ** * ** * * i,a,b;
* ***** * * *** * * * ** * * * *
******* ** * * ** ********** * * * *
*** ** ** * * ******
** * * * ** * ** *** ** ** * ***** **** ** *** * * * ** * * * *
* * **** * * ** * * * * ** * ** * ***
*** ********* * *** ** * * * * * * * * * **** ** ** * *** * * * ***
* ** ** * * ** ** *** *** * ** ** ** *
* * * *** * * * **** * ** * ** * *** if * ** * **** * * **
*** * * **** ** **** * * ** * * * * *
* ** **** * ** * * ** * * **** * * * * * * * ** * * * * ** *
** ** * * * *** *** *** *** **** * * *** ** * *
* *** *
* ** *** * * **
** * ** *** ** * ** ** * 0;
}
answered by (-196 points)
0 0
Case 0: Wrong output
Case 1: Wrong output
Case 2: Wrong output
0 like 0 dislike
Hidden content!
#include <stdio.h>
#include <string.h>
int read_line(char str[], int n)
{
int ch, i = 0;
while ((ch = getchar()) != '\n')
if (i < n)
str[i++] = ch;
str[i] = '\0'; /* terminates string */
return i;
}
int main()
{
****** *** * * * ** **** * str[100];
** * * * *** *** * * i,a,b;
* *** * * ** * *** **** **
* *** ******* * **** ** ** ** ** * * * *** *
* ** ** ** **** ** * * **
* *** * * *** * * ** * ***** *** ** * *** * * ******* ** ***
* * *** * * * * * * * * * ** * ** ** * * **
* * ******* * * **** * ***** * ** * * * * * ** ** * * ********** *** *
* * *** ** * * ****** *** * * **** * ** **
** *** ** **** **** * * * * * ******* ** * *** if ** ** * *** * * ** *** * * * *
* ** ** ** ****** *** * ****** * * **** * ***
* ** *** * * **** **** ******** * * * ****** * * *** * * ** ** *
* * * * * * * ** *** * * * ***** **
* *** *** ** * ****
**** * ** * * ** *** ** ***
*** ** ** ** * ****** 0;
}
answered by (-196 points)
0 0
Case 0: Wrong output
Case 1: Wrong output
Case 2: Wrong output
0 like 0 dislike
Hidden content!
#include <stdio.h>
int main()
{
    char a[1000];
    int i;
** * * ** * * * ** * *
** ** * * ** * * *** ** *** ** ** *
* ** * *** ** * ** ** * * * ** ** * * * *** * **** ***** * * * * ** *
* * ** **** * ** *** * * * ** **** *** * * ** * * * **** **
***** * * * ***** * *** **** * ** ** *** * ** * ** ** ** ** * *** ** * * * * *
* ** ** * *** ** ** * * * * **** * ****** * * ** * *
* * * ** ** *** *
** * ** * ** *** 0;
}
answered by (-284 points)
0 0
prog.c: In function 'main':
prog.c:6:5: warning: 'gets' is deprecated [-Wdeprecated-declarations]
     gets(a);
     ^~~~
In file included from prog.c:1:0:
/usr/include/stdio.h:640:14: note: declared here
 extern char *gets (char *__s) __wur __attribute_deprecated__;
              ^~~~
/tmp/cckMIBeA.o: In function `main':
prog.c:(.text+0x25): warning: the `gets' function is dangerous and should not be used.
0 like 0 dislike
Hidden content!
#include <stdio.h>
#include <string.h>

int main()
{
** ** ** ** * * * ** ** str[100];
    int i,a,b;
****** * ** * *
* ** ****** * * * * * *** ** ***** ** *
    {
*** * ** * ** **** ** ** * * * * ** **** * * * * * * * * * *
** * * * ** * ** *** * * * ** * ** *
** * * **** * * ** *** *** * ** **** * * * * * * ** *** ***
* ***** ** * ** *** ********** * ** ** * *
* * * ** ********* ** * **** * ***** * ** ** * *** if **** * * * *** * * ** **
* * * *** **** ** * * ** ***
* ** ** * * ** * * * *** *** *** * * **** * * * * * *
* * * ****** ** * ** * * ** * * **
    }
** ** ** * ** * ******
* * *** **** * 0;
}
answered by (-196 points)
0 0
prog.c: In function 'main':
prog.c:8:5: warning: 'gets' is deprecated [-Wdeprecated-declarations]
     gets(str);
     ^~~~
In file included from prog.c:1:0:
/usr/include/stdio.h:640:14: note: declared here
 extern char *gets (char *__s) __wur __attribute_deprecated__;
              ^~~~
/tmp/cc7O3tJu.o: In function `main':
prog.c:(.text+0x23): warning: the `gets' function is dangerous and should not be used.
0 like 0 dislike
Hidden content!
#include <stdio.h>
int main()
{
    char str[100];
    int i,a,b;
* * ** * **** * * **
** * ** *** * **** **** * *****
    {
* ** * * ** ** **** *** * **** * ****** **** * * * ** * *** * * * * ** ***
***** ** * * ** ** * * *** * *** * * *** ****
* **** * * * *** * * ** * *** ** * ** * *** * ** * * ** * *** *
* * ** * * ** * ***** * *** ***** * ******* **
*** ** * ** ** * *** ***** * * * *** * * ** if ** **** ******* * * * ** * ** **
* ** * ** ** * ** **** ** **** *** *
** ***** ** * * ***** **** * ***** * ****** ** * ** * *** *** **** ** **
* ** ** ** * * *** * * * ****** **** * *
    }
* * ** *** * * *
* ** *** * * * ****** * **** 0;
}
answered by (-196 points)
0 0
prog.c: In function 'main':
prog.c:6:5: warning: 'gets' is deprecated [-Wdeprecated-declarations]
     gets(str);
     ^~~~
In file included from prog.c:1:0:
/usr/include/stdio.h:640:14: note: declared here
 extern char *gets (char *__s) __wur __attribute_deprecated__;
              ^~~~
prog.c:7:15: warning: implicit declaration of function 'strlen' [-Wimplicit-function-declaration]
     for(i=0;i<strlen(str);i++)
               ^~~~~~
prog.c:7:15: warning: incompatible implicit declaration of built-in function 'strlen'
prog.c:7:15: note: include '<string.h>' or provide a declaration of 'strlen'
/tmp/ccX2gnMW.o: In function `main':
prog.c:(.text+0x23): warning: the `gets' function is dangerous and should not be used.
0 like 0 dislike
Hidden content!
#include <stdio.h>
int main()
{
    char str[100];
    int i,a,b;
** ** **** * ** ***
** * * ***** ***** ***** * ** ** ****
    {
* ** * **** ** *** ***** * ***** ******** ** *** * ** ** ** * * ***
*** ***** ** * ** *** ** ** * *** **
** ** *** * *********** *** ** ** * ****** * ** * ** * * * ** *** ** * *
** *** * * * * * * * * * * ** *** * * * *********
*** **** * * ** ***** *** **** * * ** * * if * *** ** ** * **** * *
*********** * * ** *** * ***** * *** **
* *** ** **** ***** *** * * ** * ***** *** *** *** * ****** * ****
*** * * *** * * ** *** * * * ** * ***** *
    }
* ** * * * * ** *** *****
*** ** * * ** *** ** ** * * * 0;
}
answered by (-196 points)
0 0
prog.c: In function 'main':
prog.c:6:5: warning: 'gets' is deprecated [-Wdeprecated-declarations]
     gets(str);
     ^~~~
In file included from prog.c:1:0:
/usr/include/stdio.h:640:14: note: declared here
 extern char *gets (char *__s) __wur __attribute_deprecated__;
              ^~~~
prog.c:7:15: warning: implicit declaration of function 'strlen' [-Wimplicit-function-declaration]
     for(i=0;i<strlen(str);i++)
               ^~~~~~
prog.c:7:15: warning: incompatible implicit declaration of built-in function 'strlen'
prog.c:7:15: note: include '<string.h>' or provide a declaration of 'strlen'
/tmp/ccxAMu40.o: In function `main':
prog.c:(.text+0x23): warning: the `gets' function is dangerous and should not be used.
Welcome to Peer-Interaction Programming Learning System (PIPLS) LTLab, National DongHwa University
English 中文 Tiếng Việt
IP:172.70.100.16
©2016-2025

Related questions

0 like 0 dislike
27 answers
[Exercise] Coding (C) - asked Jan 11, 2018 in Chapter 13: Strings by thopd (12.1k points)
ID: 41439 - Available when: Unlimited - Due to: Unlimited
| 6.2k views
0 like 0 dislike
29 answers
[Exercise] Coding (C) - asked Jan 11, 2018 in Chapter 13: Strings by thopd (12.1k points)
ID: 41436 - Available when: Unlimited - Due to: Unlimited
| 6k views
12,783 questions
183,442 answers
172,219 comments
4,824 users