strings and arrays task - Programmers Heaven

Howdy, Stranger!

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

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

strings and arrays task

illay1stillay1st Posts: 1Member
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!

Comments

  • pseudocoderpseudocoder Posts: 687Member ✭✭✭
    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
    [code]
    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
    [/code]

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