strings and arrays task

hey everybody!

i'm really new to c programing , i truly hopes to get some ideas
( hints if possible ) to a task in c that i'v been given.

the task goes like this:

1. Input the string

Description: Input the string after the following message
Please, enter your string>
Maximal allowed string length is 420. Each number in the string must be maximum
20 digits, and there must be maximum 20 numbers. In case of empty string or string
consisting characters which are not digits or spaces, as well as in case of more than
20 numbers in the string, or in case of number longer than 20 digits, the following
message will appear:
ERROR: Bad string, try again.
and the program asks to input the string again.

these are the instructions , i don't know how what is an empty string , or how should i deal with it, and what kind of variables i should use ( i'm not allowed to use string function , or any other kind of funcitons,only strings and arrays...

thank you all!


  • declare a char array
    char arr[420];

    input a string
    fgets(arr, sizeof arr, stdin);

    if it's empty
    if(arr[0] == 0)

    if it's greater than 20
    if(strlen(arr) > 20)

    non-digits/spaces may take some work
    char flag = 0,
    s[] = "123 some text 456";
    int i;

    for(i=0; s[i] != ''; ++i) {
    if(!isdigit(s[i]) && !isspace(s[i])) {
    flag = 1; break;

    if(flag == 1) ... bad string

    if you're limiting strings to 20 chars, the 420 max length seems like overkill. :P
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


In this Discussion