0 like 0 dislike
14k views

Please write a program, the user will enter a line of characters, then the program will calculate number of digits, alphabets and another characters.

寫一個程式 輸入一個字串,計算字串裡的數字、英文字母和其他符號的次數。

Example input:

1234567890Ancdefghijklmnopqrstuvwxyz~!@#$%^&*()_+

Example output:

digit:10
alphabet:26
other:13

 

[Exercise] Coding (C) - asked in Chapter 13: Strings by (5.2k points)
ID: 40715 - Available when: 2018-01-04 18:00 - Due to: Unlimited

edited by | 14k views

53 Answers

0 like 0 dislike
Hidden content!
#include <stdio.h>
#include <string.h>

int main(void)
{
    int c,digit=0,alphabet=0,other=0;
    char string[100];
* ***** * ***** * ** * ** * * *

* ** * * * ** * ** * c<strlen(string); c++)
* ** * ** * * * * **** **** ** ** * ***
* ** ***** * * ** * *** ** * * * * ** * *** * ***** ** * *
* * *** * * ** * ** *** ******* * * * ** ** ** ** *** * * * * **** ** * * * && string[c]<='Z') || (string[c]>= 'a' && string[c]<='z'))
** ** ** **** * * ** ** **** * ** * * * * * ** *****
* ******* ** ***** * * * ** *** * ***** * * * * * *** ** * **** **** ****** **** ***
*** *** * * * *** * * * ** ** ** * ** ** *** ** * ** **

* ****** *** *** * *** ** ** ** * ** * *** * * if(string[c]>='0'&& string[c]<= '9')
**** * * *** * ***** ** ** * ** * * * * *** ** * ** * * * ** *
** * * ** ** *** **** *** * * *** * *** *** * * * * ** * * * ***** ** ** ** ** * * **
* **** ****** * * *** * ** ** * ** * * * *** * ** * * *

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

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

*** ** * * * ** **** * * ***** *** *** ** ** * *** ** * *
    return 0;
}
answered by (-281 points)
0 0
Case 0: Correct output
Case 1: Correct output
0 0
Case 0: Correct output
Case 1: Correct output
0 like 0 dislike
Hidden content!
#include<stdio.h>
#include<string.h>

int main() {
* * * **** *** * ** dig=0, alp=0, oth=0, i=0, len;
* * ****** * * ** **** * * in[100];
* * ** * * ** * ** ***** {
** * * ** **** ** ** * *** ** **** ** *
* * ** **** ***** *
*** ****** * *** ** * ***** *
* ******* ** * ** *** *** * ****

**** ** * ** ** * * **** *** ***** {
* * *** ** * ** * ** ** ** * ***** * * ** * * * ** && in[i]<=57) {
**** ** *** ** * ** * * ** ** *** ** * ** * ** * **** *******
* * * *** *** * * ** ****** *** * ***** * **
** *** *** * ** *** * ** ** * ****** ** * *** if((in[i]>=65 && in[i]<=90) || (in[i]>=97 && in[i]<=122)) {
** *** ** ** *** ** * ** *** ** * ******* *** ** * * * * ** ** ** ******* ** * *** *
**** * * *** ** **** * * ******** *** *
***** * * * * *** * * ** *** * *** * ** * * {
*** * ** ** * *** ** ** ****** * ** * * ** ***** * ** * ** * * * *
** ** ***** * *** * * *** * * ** * * ** * ** **
*** ** * * ****
** * * * ************ * * * *** ***** *** * * * *** dig, alp, oth);
}
answered by (-120 points)
edited by
0 0
prog.c: In function 'main':
prog.c:10:9: warning: implicit declaration of function 'strlen' [-Wimplicit-function-declaration]
     len=strlen(in);
         ^~~~~~
prog.c:10:9: warning: incompatible implicit declaration of built-in function 'strlen'
prog.c:10:9: note: include '<string.h>' or provide a declaration of 'strlen'
0 0
Case 0: Wrong output
Case 1: Wrong output
0 0
prog.c: In function 'main':
prog.c:6:10: error: array size missing in 'in'
     char in[];
          ^~
0 0
Case 0: Wrong output
Case 1: Wrong output
0 0
Case 0: Correct output
Case 1: Correct output
0 like 0 dislike
Hidden content!
#include<stdio.h>
#include<string.h>
int main()
{

    int i,digits=0,alphabet=0,other=0;

    char str[100];
*** * * * * ** * * * * ** * * **

*** * * ** * * ***** * * ** **** **
    {
** ** *** ** * ** * *** ** * * * * ** * * ** * * ** * ** ** *** * * * str[i]>='a'&&str[i]<='z')
***** * *** ** **** *** * * * * * ***
* ** *** * * * ** ** *** * ** ** * ***** *** * * * **** * * ** * *
*** ******* * *** * ** * * **** * * * ** **
**** * * * *** * *** *** * * ** * * *** * *** ** * &&str[i]<='9'){
* * * ** * * * ** ** * * ** *** * * ** *** * * * *** ** * **
** *** **** * * *** * ** * ********* **
** * * **** * ** ** ** * ***** * * *** ** * * **** * ** * *** **** ** ****** ***** ** ** * **** * *** * * * * **** * ** *** **** *** * * *** * *** * * ******* * ** *
* *** * * * ** **** ** ** ***** * ** * **
**** * *** *** * ** * * * * * **** **** ******* * *** ****
* * *** * * * * * ** * ** *** * ** * *** ****
    }
* * ** ** * ******** ****** ** * * * * ********
* * **** ** ** * ***** *** * ** **** ***** * *
** * * * * * * * * * * ** **** * * ** **
}
answered by (-167 points)
0 0
Case 0: Wrong output
Case 1: Wrong output
0 like 0 dislike
Hidden content!
#include <stdio.h>
#include <ctype.h>
#include <string.h>
int main()
{
* **** * ** *** * * **** a[999];
* * *** *** * ******** * i,digit=0,alphabet=0,other=0;
* ** ****** ** * *** * * * * ** *** *
* * *** ***** ** * * **** * *** * *
    {
** * ** * **** ** *** * ** ** * ** *** ** ***** * *** ** ** * *** *** * ** ** *** * ** * *
** ****** ** ***** ** * ** * ********* ***** * * *
** *** *** ** ** * ** **** **** * * * * if ** * ** **** ***** ** * * ****
* * ** * * * * *** ** *** * *** *** *****
** **** * * ** ** ** ** ***** * * * * * * * *
* * * * *** ***** **** * * ** * *
    }
** ** ** * * * * * * * * *** * ****** * **
*** ** ** * * * * * * * * * * *** ** **** ***
* * * ** * * *** ** *** *** ** * ** ** * * * * * ***** **
*** * *** * * *** ** ** 0;
}
answered by (-32 points)
0 0
Case 0: Wrong output
Case 1: Wrong output
0 0
Case 0: Correct output
Case 1: Correct output
0 like 0 dislike
Hidden content!
#include<stdio.h>
#include<string.h>
int main()
{

    int i,digits=0,alphabet=0,other=0;

    char str[100];
** * *** * ** * * * * * * *** *

* *** * *** *** * *** *** * *******
    {
** * * ***** * * * ***** ***** * ** ** * * * * * ** ** ** *** ** *** * str[i]>='a'&&str[i]<='z')
*** ** ***** * *** * ***** * * * * *** ** *****
**** ** * * **** *** **** * * **** * * ****** * * ** * * * **
*** ** * ***** *** ** * * ** **** *** *** ** **
* **** *** * **** ** ** ** *** ** * * ** ** ** &&str[i]<'9'){
*** * **** **** * * * ***** *** * *** * **** ****** *** **** * * *** **
** *** ** ** ** * ***** ** ** * ** *** *** **
** **** *** **** ** * * ** * * * * ** * * ** ** *** * * ** ** * ** *** * ** * ** ** ** ** * * * * ** ** * * * ** **** ****** ***** * * * **** **
* * *** **** *** * * *** * ** ** **** *** *
* ** *** * ** * *** * ** ***** * *** ** * * ** ***
* *** ** ** ** ** *** * * **
    }
* *** ** ** ***** ** * ****** ** **** * ** *
* *** **** *** **** ******* *** ***** * **** *** **
* * *** * *** * *** * * ** ********* **** *
}
answered by (-167 points)
0 0
Case 0: Wrong output
Case 1: Wrong output
0 like 0 dislike
Hidden content!
#include<stdio.h>
#include<string.h>
int main()
{

    int i,digits=0,alphabet=0,other=0;

    char str[100];
* ** * *** * * ** * * **

* * * * * * ** * * * * * ** *
    {
* * *** *** * * ** ** ** *** ** ** * ** ** * ** **** * **** *** * ***** * str[i]>='a'&&str[i]<='z')
* * *** * *** * *** * **** * ** **** **
*** ** * * * ** ** * ***** * * * ** * *** * *** * ** * **** ****
** ** * **** * * ** * ** ** *** *** * *
** * * *** * * ** * **** ***** ** *** * ** * *** ** * * ** &&str[i]<'9'){
* ** * * ** * ** ** **** ** * *** *** ** * **** *** ** ******** ** *
** * ** ****** ** * * * * ** ******* * *** *
** *** * *** ** * * *** ** * * * ** * ** * ** * * ** * * ** **** *** **** ** ****** *** ***** ** **** *** * * ** * ** * * ** **** * *** * ** * * **** **
** * * * * ** * ** * ** * * ** ** * * ***
* * ** * * *** *** ** * * *** ***** ** *** * * * * * ** *
* *** * ** * *** ***** *** ** ** * *
    }
* ****** * * ** ** * * ** **** ** * * *** * * * *
** * * * *** ** * ** * **** ** * * ***** ** *
* *** ** * * **** ** * * **** * * ** * * *
}
answered by (-167 points)
0 0
prog.c: In function 'main':
prog.c:9:5: warning: implicit declaration of function 'fget' [-Wimplicit-function-declaration]
     fget(str,100,stdin);
     ^~~~
/tmp/ccTgeXAd.o: In function `main':
prog.c:(.text+0x52): undefined reference to `fget'
collect2: error: ld returned 1 exit status
0 like 0 dislike
Hidden content!
#include<stdio.h>
#include<string.h>
int main()
{

    int i,digits=0,alphabet=0,other=0;

    char str[100];
    gets(str);

* * * * * *** * *** ******* **
    {
**** * * ** ** * ** ** * * ** * * * **** * *** *** ** *** * * ********** * * ** * *** ** * ** ****** *
* ** * ** ***** * ** **** * * * * * * ** *
* **** ** *** **** *** * ****** * ** * **** *** ** ** * * **** *** *
* * **** **** *** ** * * **** * * **** * ** * *
*** ** * ** ** **** ***** * **** ** ** ** * * * * ** **** &&str[i]<'9'){
* *** **** ** ** * ** **** * ** * ** * * * * * ****** *
** * ***** * ***** * ***** * ** * ** ** * * ***
* * * ** * ** ** * * **** **** * ** ** ** * * * * ** ********* ** * * * * ** ** * ** * ** * * * ** ** * ***** ******** ** * ***** *** ** ** * * * *
*** ** * * ******* * ** * ** ** * **** **
** * *** ** ** * *** **** * *** ** * * **** * * * * *** *
****** * * **** * ** *** * * * * ** * ** *
    }
* * * *** ** * * * *** ** ***** * *** * ** * * *
* * * * ***** ** **** * * ** * *** *
** * * * * ** * ** * ** ***** * ** *** *
}
answered by (-167 points)
0 0
prog.c: In function 'main':
prog.c:9: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/ccZyp9Qc.o: In function `main':
prog.c:(.text+0x41): warning: the `gets' function is dangerous and should not be used.
0 like 0 dislike
Hidden content!
#include <stdio.h>
#include <ctype.h>
#include <string.h>
int main()
{
** * * * **** * ** * * A[999];
*** ** ***** * * * * **** ** ** **
** * *** ******** **** * * ** * ** *
* ** ** * ** * ** * * **** * *
*** ** * ** **
*** * **** *** * * * ** * * * * ** *** ** (tolower(A[i])>='a' && tolower(A[i])<='z')
* ** * * **** ** *** *** * * ** ** *** ** * * *** * ** ** **
*** ** * *** ** *** * * ** * * **** ****** if (A[i]>='0' && A[i]<='9')
* * **** * * ****** * * *** * * *** *** * ** **** **** * * **
** ****** * * * * ** * * ** *** * * * *** * * * **
* * * ****** * * * ** ** * * *** * * *** * ** *** *** * **** * *
* * * ***** * ****** *
** *** *** ** **** * ** ******* * *** * * *** * * * ** **** ** * * * * *
** * ***** * *** **** * ** 0;
}
answered by (-249 points)
0 0
Case 0: Wrong output
Case 1: Wrong output
0 0
Case 0: Correct output
Case 1: Correct output
0 like 0 dislike
Hidden content!
#include <stdio.h>
#include <string.h>
#include <ctype.h>

int main()
{
** ** * * *** ** * * arr[999];
* ** * ** * * **** * * * i,digit=0,alphab=0,other=0;
* * **** ****** * ** *** **** *** * * *
**** * *** ** * * * * ** **
* * * * * ** * **
* *** ** *** * **** * * * * ** ****** (arr[i]>='0' && arr[i]<='9')
* * * * ** * * * * * **** ** ** * *** ** * *** * * **** * *
* ** **** ** *** ** ** * ** * * * * **** ** * ** * if * ** * * * **** && tolower(arr[i])<='z')
**** * * * * * ** * * * ** ** *** ** ** ** * *** *** * ***** *** *
* ** * ** * **** *** * * * * ** * *** **
** ** ** ***** * ** *** * ** ** ** ** ** * * ** * * ** **
* * *** ************ ***
* * ** * *** ******* * * ** * * * * ** ** * ** * ** * ** * *
* * ** ** ** ** ** * *** *** 0;
}
answered by (-249 points)
edited by
0 0
prog.c: In function 'main':
prog.c:8:16: warning: implicit declaration of function 'strlen' [-Wimplicit-function-declaration]
     for (i=0;i<strlen(A);i++)
                ^~~~~~
prog.c:8:16: warning: incompatible implicit declaration of built-in function 'strlen'
prog.c:8:16: note: include '<string.h>' or provide a declaration of 'strlen'
prog.c:15:61: warning: incompatible implicit declaration of built-in function 'strlen'
     printf("digit:%d\nalphabet:%d\nother:%d",digit,alphabet,strlen(A)-digit-alphabet-1);
                                                             ^~~~~~
prog.c:15:61: note: include '<string.h>' or provide a declaration of 'strlen'
prog.c:15:43: warning: format '%d' expects argument of type 'int', but argument 4 has type 'long unsigned int' [-Wformat=]
     printf("digit:%d\nalphabet:%d\nother:%d",digit,alphabet,strlen(A)-digit-alphabet-1);
                                           ^
0 0
prog.c: In function 'main':
prog.c:16:43: warning: format '%d' expects argument of type 'int', but argument 4 has type 'size_t {aka long unsigned int}' [-Wformat=]
     printf("digit:%d\nalphabet:%d\nother:%d",digit,alphabet,strlen(A)-digit-alphabet-1);
                                           ^
0 0
Case 0: Correct output
Case 1: Correct output
0 like 0 dislike
Hidden content!
#include <stdio.h>
int main()
{
**** *** ***** ** * * ** ** input[100];
* * * *** * ** * ** ** alp=0, dig=0, oth=0, i;
** ** *** * **** * ** * * * ** * * * **
** * * * ** * * ** * **** * * * **** *
    {
* *** * ** ** ** * *** ******* ** ** *** ** * ** * ***** && input[i]<='z') || (input[i]>='A' && input[i]<='Z'))
***** *** * ** * * ** * *** ** ***** * * * **
* ** * **** * *** * *** ** * *** * * * **** * * **
* **** **** ******* ** *** * * ** * * * *
* *** ** ** * * * * *** ** ** * * * ** *** if(input[i]>='0' && input[i]<='9')
* ***** **** ** ** * ** ***** * * * *** *** *****
* * ******** ** * **** * * *** **** * ** * **** * *** *** * **** ** **
* ** **** *** * * * * * * * **** *** *
* * * ******* ** * **** ** * * * * * * **
** *** ** ***** * * * **** * * ** * ** *** *
** * *** **** * * *** ** * * *** * ** ***** ** *** *** * * * ** **
*** * * * * **** **** * * ** * ** ** *

    }
* * *** ** * *** * ** * * *** * ** * * *** * * dig);
**** ** * * * ***** ** * *** * * ** * * ** ** *** alp);
**** * ** ** **** ** * * * * * *** oth);

** *** * **** **** ***** * 0;
}
answered by (-304 points)
0 0
Case 0: Correct output
Case 1: Correct output
Welcome to Peer-Interaction Programming Learning System (PIPLS) LTLab, National DongHwa University
English 中文 Tiếng Việt
IP:172.69.214.38
©2016-2025

Related questions

0 like 0 dislike
53 answers
[Exercise] Coding (C) - asked Jan 4, 2018 in Chapter 13: Strings by semicolon (5.2k points)
ID: 40713 - Available when: 2018-01-04 18:00 - Due to: Unlimited
| 11.9k views
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
| 10.7k views
0 like 0 dislike
44 answers
[Exercise] Coding (C) - asked Jan 4, 2018 in Chapter 13: Strings by semicolon (5.2k points)
ID: 40714 - Available when: 2018-01-04 18:00 - Due to: Unlimited
| 10.5k views
12,783 questions
183,442 answers
172,219 comments
4,824 users