0 like 0 dislike
13.2k 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 | 13.2k views

53 Answers

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

int main()
{
******* * * * ** string[100];
* * ** * * ** * * *** ** * s = string;
* ** * * ** ** * ** ** ** a,d,o;
    
    a = d = o = 0;

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

*** * * * ** *** ** ** *
* * * * ***** ** * *
* * * ***** ****** * ** ** * ** * * ** ** * ** >='a' && *s<='z') || (*s >='A' && *s<='Z'))
* * **** ***** * ** ** ** * *** *
*** * ** * ** * *** ***** * * * ** * **** ** * * * ** *
* ** * * * ** ** * * * *** * *
* * * *** * * ** ** * * *********** ** ** ** ** * if(*s>='0' && *s<='9')
*** ** * **** * **** ** ****** * **** ** *
******* ** ** * ** * ** * ** * **** * ** * * * ** ****** * **
* ** * * * * * * ** ** * ****** * ** * **
* **** ** **** * *** * * * *** ** *** ** *
*** * * ** * ** * * * ** ** * ** **
** *** * *** * ***** ** ** * * * ** * * ** * * * ** ** ** ***
* ** ** *** *** * ***** ** ** ****** *
* *** * ** ** * *** ** * ** * ** **
* * ** **** ** ** * * *** * * * ***** ** * *
    }
** *** * **
* * ** ** * * **** * **** * **
** ** *** ** * * * ** * * * * ****** * *
* *** * * ** *** ** *** * * ** *
    
*** * *** * * *** ** * * 0;
}
answered by (-193 points)
0 0
Case 0: Wrong output
Case 1: Wrong output
0 like 0 dislike
Hidden content!
#include <stdio.h>

int main()
{
* * ** * * ** ** **** ******* string[100];
*** ***** * **** ** ***** * s = string;
** ** *** ** ** ** * * a,d,o;
    
    a = d = o = 0;

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

* * * * ** *** *** * *** *
****** ** ** * *** * * ** *
***** ** ** * * ** * * * * * * ** *** ***** >='a' && *s<='z') || (*s >='A' && *s<='Z'))
**** *** * * * ***** * *** ** **** *
***** * ***** * * *** ** ** *** * * * * ** * * ** ** * ** *
** ** ** ***** * ** *** * ** * **** * * **
* * * ** * * * * * ** ** * * * ** * if(*s>='0' && *s<='9')
* * * ** * ****** ** ** * * * *
* * * *** * * * ** * ** ***** * *** * * *** * ** * ** * * * *
* ** *** ** ***** * ****** * ** ** ** ***
* ****** * * * * * ** * ** * ****** * **** *
* * ** ******* ** ** ******* * ** * * *
*** * * * ******** ***** * * ****** *** * * ** **** ******** * * *
* * *** * * *** * *** * * *** * ** **
* * **** ** * *** * ** * ** * ** ** **
** *** *** **** * ** ** * ********* * ******* ** * * * *
    }
* * * * * ** * * *
* * ** * * ****** * * * ** * * * *** ** *
** ** ** ** * **** * * * * * * * ** *** ** * * *
** * * ** * * * *** * *** * ** ** ** *
    
* *** *** * ** * * * * 0;
}
answered by (-193 points)
0 0
Case 0: Wrong output
Case 1: Wrong output
0 like 0 dislike
Hidden content!
#include <stdio.h>

int main()
{
* * *** ** * **** ** ** * str[100];
******** * *** * ** * * alphabets, digits, others, i;
    
** ** ** *** ** * * = digits = others = i = 0;
    
** * ** * ** * ****** ** ** **
* * * **** ** *** * * ** **
* ** ** ** *** * ***** *
**** *** ***** * * *** * ** * * * * ** *** * * ** ** *** && str[i]<='z') || (str[i]>='A' && str[i]<='Z'))
** * ** * ****** * * * * * ** * * ** *** ** *
** *** * * ** * * * * * ** * * * * * *** * * *** ** ** * * *** * * *
* **** * ** ** * * * * * * * *** * **
* ** * ** * ******* ** ** * ** * ** * * * ** * ** *** * if(str[i]>='0' && str[i]<='9')
* * ** * * ** * ** * ** *** ***** **
* *** ** * **** * ** * * * ** * ** * ******** ** ** ** *** ** *
**** * * * * * ** * ** ** * ******
** ** * * ** * * * **** * *** * ** ********* ** *
****** * ** * ** ***** *** * ** *** * *
* * * ***** * * * * ** *** ******* *** * *** ** ***** *** * ****
** ****** ****** **** ** **** ***** *** *** *
** *** ***** **** * * ** ** ** * * ** *****
* ** * * ** * **** ** *
* ** ** * * ** * **** *
** * * *** ** * ** ******* ** ***** ******* digits);
****** ***** ** * *** *** *** * * * *** * *** alphabets);
* * *** ******* ** * * * ** *** * others);
    
*** *** * *** ** * * 0;
}
answered by (323 points)
0 0
Case 0: Wrong output
Case 1: Wrong output
0 like 0 dislike
Hidden content!
#include <stdio.h>

int main()
{
**** *** ** * * ** str[100];
**** * * ** *** * *** ** ** ** * alphabets, digits, others, i;
    
** * ** * ** *** * ** *** = digits = others = i = 0;
    
** * ** * * * * * *** ** * * *
* * *** * * * * * * * ** *
* ** * ** * ** * * *
* * * ** * * * * * ** *** *** ** ** * * ** * ** && str[i]<='z') || (str[i]>='A' && str[i]<='Z'))
* * ** * ** * * ** * * * * * * * **
** ** *** **** *** ** ******* * * ** * * **** * ********** * *** * * **
* * * *** * * * ** * * * ** * ** * * *** **
** ** ** ** * ** **** *** * ** * *** if(str[i]>='0' && str[i]<='9')
** ** * * * * * * * * ** * * *
** * * * * **** ** ***** * *** * ** * ** * **** * **** ***** * **
** *** ** *** *** * * ** ** ** * ****
******* ** **** **** * * *** * * *** * ** ****
* ** * *** ******* ** * * ** ** ****
* * **** * * * ** * ** * ** * * * ****** * ***** * * * ** * *** * **
**** * *** **** * **** * * * * ***
*** * ** *** **** * *** *** ** * * ** * ** * * *
* * ** ** *
******** ******* *** ****** * *
*** ** * ** * ** * ** * ** ** * digits);
* * * ** * * * ******* **** ** * ** **** * *** * alphabets);
* * *** * *** ** * * * * ****** **** * others);
    
* **** ** ** * ** 0;
}
answered by (323 points)
0 0
Case 0: Wrong output
Case 1: Wrong output
0 like 0 dislike
Hidden content!
#include <stdio.h>

int main()
{
* ** ** * * * * ** str[100];
* * * ** * ** * * ** alphabets, digits, others, i;
    
* **** * * *** ***** = digits = others = i = 0;
    
* * * * **** * * **** * *
* * *** * * * * * * **
* ** * ** * **** ** *
* ** ** * * **** ** * * *** *** ** *** ***** * * * && str[i]<='z') || (str[i]>='A' && str[i]<='Z'))
***** ****** * * ***** * * * * *****
* *** * * * **** * ** * ** * ** * ** **** * ** * * ** * ****** * ** **
**** * * ****** * ** * * *** ****** * *
***** * * **** * *** * * ***** ** ***** ***** * *** * * if(str[i]>='0' && str[i]<='9')
** * *** ** ** ** ** * ***** *** * *
* ** * * * * ** ** * *** ** ** ** ***** *** *** ***** **** * ****
**** * * * * ** *** * * * * ** * * ***
* * ***** *** ** *** * * * ** ** * **** * *
** * * **** *** *** *** * ** * ***** * *
* * ** ** * * * ** ** * ** * * ** **** * ** *** *** * ** ** **
** ****** * * * ** * ** ** * * * *** ** * **
** ** *** * ***** ** * **** * *** * ** ** * ***
** **** *********** * * * *
*** * **** ** ** ** * ****** **** *** ** *** digits);
*** * ** * * **** ** *** ***** * * alphabets);
** * * ** * * *** * ** * * * ***** * * others);
    
***** * * *** * ****** 0;
}
answered by (323 points)
0 0
prog.c: In function 'main':
prog.c:10: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/cco6wl33.o: In function `main':
prog.c:(.text+0x38): warning: the `gets' function is dangerous and should not be used.
0 like 0 dislike
Hidden content!
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define LEN 300
void main(){
          int digit=0,alphabet=0,other=0;
* * * * ** * * * * *** * * * * *** * * * * * s[LEN];
* ** * ** * * *** * ***** ** ** * * ** ** * * * i,l;
* ** ** *** **** ** ** * ** ***** * ** * * *** *** * * * *
          {
** * ** ** * * ** * **** * ** ** * ***** * * ** * * * * *** * ** ** * * ***
          }
*** * * *** * ******* * * ** * ** **** ** * ** * * *** s);
* * ** **** * * * ** ** * * *** ** * *** ****** * *** * ***
* * * ***** *** *** ** * *** * * ** * * ** *** * ** * * * * **
          {
* * ** ** *** ** * ** ** ** *** * ** * *** *** ** ** * * * ** * * *** * * *** *** ** *** ***
** * * * * ** * ****** **** * ******* ** **** ** *** * ***** * * * * *** * ****** **
****** ** ** * * * ** ** * * * * ** * ** * ** * * * * ** * * * * ** * * ** * * ** * ****** * **** *
** * ** ** * ** * **** ** * ****** * * * * * **** * ** *** *** * ** ***** ** **
** ** * * * * ** **** * * * *** * * * **** * * * ** * * * **** ** **** ** * * ** * ** *** * * * *** * * * ***** * **
* ** * *** * *** * *** *** *** ** * ******* ** ** *** * **** * ** *** * *
* * * * * * * * * *** *** ** * * * * * *** *** *** * * **** *** * * ****** * ** ** * *** * * * * ** *
* **** ** * **** ** ** ** *** * ***** * ** ** * * * * ** * * ** * *** *** **
**** ****** **** ** *** * * ********* * ** ** * *** *
* * * ** * ********** ** * **** * ** ***** ** *** * ** * *** ** * * * * *** * *
** *** *** * * ** ** ** ** * * * * * * ** ** * * *** *** * * * * * ***** * ** ** ** * * * **
** ** * ** ** * * * ***** * *** * **** *** ** * **** * * * * ***** * * *
          }
* **** ** * ** **** * ** * *** ** *** ** ** * ** * *** * * * *** * *** * * *** * *
* ***** * ** *** * ** * **** * * * ** ** ** ** **** * *** ** **
** * * *** ** * * *** ** ** **** ** * *** * *** ***** * *** *
}
answered by (-32 points)
edited by
0 0
prog.c: In function 'Input':
prog.c:9:19: warning: assignment makes integer from pointer without a cast [-Wint-conversion]
               s[i]=NULL;
                   ^
prog.c:13:26: warning: 'return' with a value, in function returning void
                   return -1;
                          ^
prog.c:4:6: note: declared here
 void Input(char n[]){
      ^~~~~
prog.c:20:11: warning: implicit declaration of function 'Count' [-Wimplicit-function-declaration]
           Count(s,l);
           ^~~~~
prog.c:21:18: warning: 'return' with a value, in function returning void
           return 0;
                  ^
prog.c:4:6: note: declared here
 void Input(char n[]){
      ^~~~~
prog.c: At top level:
prog.c:24:6: warning: conflicting types for 'Count'
 void Count(char n[],int l)
      ^~~~~
prog.c:20:11: note: previous implicit declaration of 'Count' was here
           Count(s,l);
           ^~~~~
0 0
prog.c: In function 'main':
prog.c:10:19: warning: assignment makes integer from pointer without a cast [-Wint-conversion]
               s[i]=NULL;
                   ^
prog.c:12:19: warning: format '%s' expects argument of type 'char *', but argument 2 has type 'char (*)[300]' [-Wformat=]
           scanf("%s",&s);
                   ^
0 0
prog.c: In function 'main':
prog.c:11:19: warning: assignment makes integer from pointer without a cast [-Wint-conversion]
               s[i]=NULL;
                   ^
prog.c:13:19: warning: format '%s' expects argument of type 'char *', but argument 2 has type 'char (*)[300]' [-Wformat=]
           scanf("%s",&s);
                   ^
0 0
prog.c: In function 'main':
prog.c:11:19: warning: assignment makes integer from pointer without a cast [-Wint-conversion]
               s[i]=NULL;
                   ^
prog.c:13:19: warning: format '%s' expects argument of type 'char *', but argument 2 has type 'char (*)[300]' [-Wformat=]
           scanf("%s",&s);
                   ^
0 0
prog.c: In function 'main':
prog.c:11:19: warning: assignment makes integer from pointer without a cast [-Wint-conversion]
               s[i]=NULL;
                   ^
0 0
Case 0: Correct output
Case 1: Correct output
0 0
prog.c: In function 'main':
prog.c:13:19: warning: format '%s' expects argument of type 'char *', but argument 2 has type 'char (*)[300]' [-Wformat=]
           scanf("%s", &s);
                   ^
0 0
prog.c: In function 'main':
prog.c:13:19: warning: format '%s' expects argument of type 'char *', but argument 2 has type 'char (*)[300]' [-Wformat=]
           scanf("%s", &s);
                   ^
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 b,d=0,al=0,o=0;
    char a[1000];
**** **** * * * * ** * * ** *******
** * * *** * ** * ** * ** **** *
*** * ** * * * ** * **** * ** ** *** ** * * *** *** ** * ** * ** **** **** * ** * ** ** *
* * * * * * ** ** * * * *** * * ** * * **** ** * ** ** * * * *
** **** * **** ** ** * ******** ** * ** * * * * *** ** ** * * * ** * ** *
* * * *** ** * * * * *** * ******* * * ** *** * * *****
* * * **** * * ** ** * * ** **** *
* * * * * * **** **** *** * * *** * * * ** ***** * * *** *** *****
    }
* *** *** * **** ** * ***** *** * * * * *
** **** ** * * **** *** ****** **** * **** ** ** *** *
* * *** * ** * * *** ** * **** * ** * *** * *
**** ** * ** ** * * * * 0;
}
answered by (-498 points)
edited by
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()
{
    int digit=0,alphabet=0,other=0;
    int i,n,x;
    char a[100];
* * ** ******* * * * *** **** **** * ** * **
* * * ** ** * * * * * *****
* * **** *** * ** ** ** ** ** * *
* * * * *** ** ** * ** ** * * * *
* ** * ** * ** * ** *** * ***** ** *** ******** * && x<58){
* * ** * * * * ** ** **** * *** * ** ** * ** * * * ** * **
* * * * ** * * *** * * ** *
* ** * * * * * **** * *** ** *** ** * if(x>64 && x<91){
* ** * * * * ** * **** ** ** ** * ** ** ** *** * * ** ** ** * ***
* ** * * * *** * * * * ** ** * ** ******
*** *** * * * * ** *** * *** ** *** ** **** if(x>96 && x<123){
*** ********** **** * * * * * * ****** ** * *** * ******* * *** *** * ***** *
** * * * *** ** *** ** *** * * * ****
* ** ***** * *** *** * * ** * ** * * ** ***
* * * ** ** *** * * * * * * ** * * * * * * * **** * *
***** * *** * ***** * * * ** * * **
* ******** *** ** * * * ** * ** ** ** *** * *** ** * * ***** ** *
    }
*** ***** ********* ** * ** * * * * * ** **** *
* * * * * * **** * * *** ** * ** ** *** **** *
* *** *** * *** **** * ** * * * * * ** *******
* **** * ** * * ** **** 0;
}
answered by (54 points)
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 n=0,j;
    int alphabet=0;
    int digit=0;
    int other=0;
    char word[1000];
*** * * ****** ** ****** *** *** *** *
* * ****** * * * * * ** * ** **** * ** * * * //strlen is array ,begin from 0
* * * * *** ** * ** *** * *** *
*** * * * *** ** **** **** * * *** * ** **** * ** ** * * * * ***** ** && word[n]>=97)
****** *** ** **** * * *** ** **** *** **** *** ** ** ** ** ******* * ** * ** **** * * * * **** * ** * **
* * *** * * * ***** * **** * ***** * ** *** * ** * * ** ** * *** * ** * * * ** ** * ****** * ***** * * * ******
** *** * * ** *** ****** * *** ** ** * *** ** ** * * ** * ** * ** *** ***** *
***** ** * ** ****** **** * * * * * * * ** **** ** * ** * * * * if(90>=word[n] && word[n]>=65)
* *** * ** **** * * *** * ** * *** * ** * **** * * *** ** * * ***** ** * * * * * *** * **
***** *** * *** ** **** *** *** *** * ** * * * * * ** ** * * ** * * * * * * ** * ** * * **** * *
*** *** * * *** ** ** **** * *** ** ** **** *** ** ** ** ** ** ** * * ** *** *** **** *

* * *** ***** *** ** * ** * * ** * * * * ** * ***** **** ** if(57>=word[n] && word[n]>=48)
* ** ** * ** **** ** ** ** * * ***** * * ** *** ** ** * * * * * * ** * *** ** ** * *
***** ** * * ** ** * ** * *** **** ** **** * * * * ** *** **** ** *** ***** * * ** ** *** * * * **** * * * ** ** **
* * * ******** ** * **** * *** * * * * * ** * ** ***** * ** * ** * * ** * ***** *

* *** * *** * ** ** **** **** * **** * * * * * ** ** * *** * other++;


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

}
answered by (-301 points)
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 n=0,j;
    int alphabet=0;
    int digit=0;
    int other=0;
    char word[1000];
* * * * **** ** * * * ** ** ** **
** * ** * * *** * * * * * * * //strlen is array ,begin from 0
* * ***** * ** ** ** ** **** ** * ** *
* * ** ** * **** * * * * ** *** ** ** * * ** * * *** ** ******* *** * && word[n]>=97)
* **** * * * * ** *** *** * ** **** *** ** * *** * *** * ***** * ****** * *** * **
** * * ** * * * * **** * ** * ** ** **** *** ** * ** ** * ** * ** * * * ** * * ** * * ** * ** * * ** **** * **
** * * **** ** * * **** * * **** *** ** * * * ** ** *** * * * * * * * ** * * * **
* * *** ****** ** * * * **** ** * ** * * * * * * ** ** if(90>=word[n] && word[n]>=65)
*** * * * *** * * *** * * *** ** ** * * * * ** * * * ** ** * * ** *** *** * *** *
* ** * ** ** *** * * * * *** ** * * **** * * * ***** * * ***** * *** ***** **** * * * ***** * * **** ** ** * *
* * **** *** * ** ** **** * *** ** * ** *** * ****** ***** * ** * **** * ** * **** ** *

* **** ** ** * ** * * * **** *** ****** * ** * ** * * if(57>=word[n] && word[n]>=48)
** ** ** * * * * * ** * * **** * ** **** * * **** * * * * * *** * * ****
* * ** * ** * ** * ***** ** ** *** ** *** * *** * * *** * * * * ****** ** * * *** * ** * * * * * * * * ** **
* *** * ** * * * * * **** * * * * * * * *** * * * *** ** * * ** * * * ** ** ** ** * ***

* * ** * * * ** * *** * *** ** * * *** * ** ** * * *** * other++;


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

}#include<stdio.h>
#include <string.h>



int main()
{
    int n=0,j;
    int alphabet=0;
    int digit=0;
    int other=0;
    char word[1000];
*** ** *** * * * **** * * * *** *
*** ** *** * ** ** ** ** * *** //strlen is array ,begin from 0
*** * * * ** **** * *** * ** * ******
* ** * * ** * *** ** * * * ** * ** *** ** * * * *** * ****** && word[n]>=97)
** ** * ** ** ** * *** * **** * ***** * *** * ** ** ** **** ** ** ** * ** * * *** **** ** * *
* * * *** * * * * ** * *** **** * * * ** * * * * *** ** ** * * * ** *** ** ** * * **** ** * * * *** ** ****
* *** **** * * **** ** * ** * * * *** ** * * * * *** ****** * ** ** * * *** *
* ** * * * * * * * ** ** *** * * * *** if(90>=word[n] && word[n]>=65)
* * ** * * *** * **** ** * * *** ** * ** * **** * * ** * * * * * * * * **** * * ****
* * ***** * **** **** **** * ** * ********* ** ** ** * * ** **** ** * ** **** ** * * ****** * * * * * * * * *
** *** *** ** ******** * * * * ** * ******** * * * * * * ***** *** ** * ******* * *

* ******** ** **** * * * ** * ** * * *** ** * if(57>=word[n] && word[n]>=48)
** * ** ** ** ** * *** * ** **** * *** * * *** * ** * ** ** *** * * ***** * * * * ** ** * *
* ** * ******* **** * * * *** * * * *** *** ** ** * * ********* *** * ** ******* ****** ** * ** * *** *** * *** *
** ** * ** * **** * ******* ** * ** * * ** ** * ** * * * *** * * * * *** *

**** * * * * * *** * ******* * ***** * *** * * *** * * * * **** other++;


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

}
answered by (-301 points)
0 0
prog.c:36:2: error: stray '#' in program
 }#include<stdio.h>
  ^
prog.c:36:10: error: expected '=', ',', ';', 'asm' or '__attribute__' before '<' token
 }#include<stdio.h>
          ^
Welcome to Peer-Interaction Programming Learning System (PIPLS) LTLab, National DongHwa University
English 中文 Tiếng Việt
IP:172.69.130.53
©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.2k 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
| 9.9k 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
| 10k views
12,783 questions
183,442 answers
172,219 comments
4,824 users