Thread: My Upper Letter Function Doesnt Work

  1. #1
    Registered User
    Join Date
    Dec 2016
    Location
    Turkey
    Posts
    2

    Question My Upper Letter Function Doesnt Work

    Hello. I am a student at computer enginnering tonight ı was working on C (ı am using visual studio 15). I have project which is have to find 2 thing.
    First it have to count letter of the entered word.
    Second have to change all letters upper.
    So ı decided to make two different function (bec of optimization)
    But ı am getting error.

    Here List Of Errors

    4th line expected an identifier(Active Error)

    4th limesyntax error : '<parameter-list>'(Only Error)
    5thSatır expected a')'(Active Error)
    7thSatır expected a')'(Active Error)




    Code:
    #include<stdio.h>#include<ctype.h>
    
    
    (int büyükharfler(char dizi[])
    {
       int i = 0;
        while  (i = 10; dizi[i] = '\0'; i++)
            dizi[i] = toupper(dizi[i]);
        return 0;
    
    
    }
    
    
    int strlen(char dizi[])
    {
        int i = 0;
        while (dizi[i] != '\0')
            ++i;
        return i;
    }
    
    
    int main()
    {
        char a[10];
        printf("Enter a String(Word) (MAX 10 CHARACTER):");
        scanf("%s", &a);
        printf("Len of %s %d", a, strlen(a));
        printf("Büyük Harflerle %s %d", a, büyükharfler(a));
        getchar();
        getchar();
    }
    So ı hope someone tell my mistake thx a lot

  2. #2
    Registered User
    Join Date
    Jun 2011
    Posts
    4,513
    Code:
    (int f(char dizi[])
    You have an open parenthesis where it doesn't belong.

    Code:
    while  (i = 10; dizi[i] = '\0'; i++)
    This is the set-up for a for() loop, not a while. Also be aware of the difference between = and == (though I suspect you want != ).
    Why are you starting the count at 10?

    Code:
    int strlen(char dizi[])
    "strlen" is the name of a standard library function in "string.h". You should make the name of yours unique, such as "my_strlen" or some such.

    Code:
    scanf("%s", &a);
    You do not need the & here. An array name by itself acts as a pointer to its first element.

    Code:
    char a[10];
    printf("Enter a String(Word) (MAX 10 CHARACTER):");
    This array can only hold a string of length 9 (the last element needs to be reserved for the terminating '\0'). Speaking of which, you should limit the characters scanf() will read to avoid overflow: scanf("%9s", a), or just use fgets().
    Last edited by Matticus; 12-20-2016 at 03:36 PM.

  3. #3
    Registered User
    Join Date
    Jun 2015
    Posts
    1,640
    Code:
    #include<stdio.h>
    #include<ctype.h>
     
    //// You have a stray open parenthesis here for some reason.
    //// You probably shouldn't be using extended characters in identifiers.
    //// I don't know anything about that, though.
    //// Maybe your compiler doesn't complain about it, but mine does. 
    (int büyükharfler(char dizi[])
    {
        int i = 0;
        //// This is a for loop, not a while loop.
        //// And you need to use == to compare for equality, not =
        while  (i = 10; dizi[i] = '\0'; i++)
            dizi[i] = toupper(dizi[i]);
        return 0; 
    }
     
    //// You shouldn't name your function with the same name
    //// as a standard library function.
    int strlen(char dizi[])
    {
        int i = 0;
        while (dizi[i] != '\0')
            ++i;
        return i;
    }
     
    int main()
    {
        char a[10];
    
        //// Since a C-string uses a '\0' char to mark the end,
        //// the maximum number of chars the user can enter would be 9.
        //// If you need it to be 10, make the size of a 11.
        printf("Enter a String(Word) (MAX 10 CHARACTER):");
    
        //// The name a an array becomes a pointer to its first element in
        //// most expressions. Therefore, you shouldn't use the & here.
        //// Also you should limit the maximum number of chars that will be read
        //// by putting that number (one less than the array size) between the
        //// % and the s in the format.
        scanf("%s", &a);
    
        printf("Len of %s %d", a, strlen(a));
    
        //// It doesn't make sense for you to print the return value of büyükharfler.
        //// Actually, it probably should be a void function (no return value).
        //// Just call it before the printf, then just print the array.
        printf("Büyük Harflerle %s %d", a, büyükharfler(a));
    
        //// This is always sad. Can't you set your IDE to keep the window open?
        getchar();
        getchar();
        
        //// You should return 0 at the end of main.
    }

  4. #4
    Registered User
    Join Date
    Dec 2016
    Location
    Turkey
    Posts
    2
    Thanks a lot. I understand every single point but ı want to ask something esle.
    Code:
    scanf("%s", &a);
    ve dont need use to & for scanning because my entered word is string?

  5. #5
    Registered User
    Join Date
    Jun 2015
    Posts
    1,640
    Quote Originally Posted by korayaykor View Post
    we dont need use to & for scanning because my entered word is string?
    scanf must be passed a pointer to the memory location where you want the input to be stored. If you want to read something into an int, you need to pass its address (memory location) so that the value can be stored there. If you want to read chars into a char array, you need to pass the address of its first location. In C, the name of the array acts like a pointer to its first element in most expressions. Since its already a pointer to the first element, you don't need to (and shouldn't) put the ampersand in front of it. If you turn up your compiler warning level, it should warn you about it.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. my display function doesnt work
    By traviidon in forum C Programming
    Replies: 1
    Last Post: 03-26-2016, 12:38 PM
  2. why this valud function doesnt work..
    By transgalactic2 in forum C Programming
    Replies: 8
    Last Post: 01-31-2009, 02:00 PM
  3. letter to upper
    By k1ll3r in forum C++ Programming
    Replies: 30
    Last Post: 05-25-2006, 02:13 AM
  4. Why doesnt this work
    By Jotun in forum C++ Programming
    Replies: 3
    Last Post: 04-18-2004, 04:55 PM
  5. Why Doesnt This Function Work ??
    By Unregistered in forum C Programming
    Replies: 2
    Last Post: 10-23-2001, 09:07 PM

Tags for this Thread