1

I am building a program that should find a char in a string according to lower case alphabet.

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

int main()
{
    char str[];
    int i;

    for (i = 0; i < strlen(str); i++)
    {
                if (str[i] < 48 || str[i] > 57)
                break;
    }
    return 0;

}

I've never had this problem before and I used incomplete types (arrays and strings) hundered situations.
Anyway, Visual Studio 2012 alerts about incomplete type:

1   IntelliSense: incomplete type is not allowed    Visual Studio 2012\Projects\C\C\main.c  6   7   C

What is wrong?

3
  • You have not defined the length of the string (char array) Commented Apr 10, 2014 at 22:43
  • 1
    "I used incomplete types (arrays and strings) hundered situations" -- Not likely. Note that char str[] as a parameter is not an incomplete type; it is equivalent to char* str in that context. (If you were to replace char str[] with char* str above, that would be undefined behavior and the program would probably crash.) And char str[] = "abc"; is also not an incomplete type -- the array size (4) is determined from the initializer. Commented Apr 10, 2014 at 23:18
  • if (str[i] < 48 || str[i] > 57) this sort of thing is useful for entries in "Obfuscated C" contests but is awful practice otherwise. Commented Apr 10, 2014 at 23:21

1 Answer 1

7

You must specify array size when you declare an array without initializer.

char str[SIZE];  
           ^Size of your array.
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.