Thread: why stop working?

  1. #1
    Registered User
    Join Date
    Oct 2013
    Location
    greece
    Posts
    87

    Question why stop working?

    why crases? it prints the capital and then crases...help plz
    Code:
    #include<stdio.h>
    #include<string.h>
    #include <ctype.h>
    main()
    {
        char sent[200];
        int i,j,count;
        printf("dwse protash :\n");
        gets(sent);
        count=strlen(sent);
        for(i=0;i<count;i++)
        {
            putchar (toupper(sent[i]));
        }
    for(i=0;i<count;i++)
        {printf("%s",sent[i]);}
    return 0;
    }
    Last edited by wesdom; 11-17-2013 at 04:58 AM.

  2. #2
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    The variable countz on line 9 is not declared. Your program shouldn't compile.
    If you change the variable to count then the reason for the crash is the format of your printf call. "%s" is used for strings you want to print chars. Use "%c"
    Kurt

  3. #3
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    1. use compiler with more warings - like gcc with -Wall
    2. read FAQ about main()
    3. read FAQ about gets
    4. indent your code properly
    5. %s in printf expects pointer to char
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  4. #4
    Registered User
    Join Date
    Oct 2013
    Location
    greece
    Posts
    87
    yea i know i run it for count i just coppy the wrong code...but anyway the idea is the same why crases??

  5. #5
    Registered User
    Join Date
    Oct 2013
    Location
    greece
    Posts
    87
    so you say the problem might be in %s... xmmm i will read thenx anyway

  6. #6
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    Quote Originally Posted by wesdom View Post
    yea i know i run it for count i just coppy the wrong code...but anyway the idea is the same why crases??
    So you expect that people will still provide sensible answers if you provide the wrong information? Few members of internet forums have mindreading skills.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 17
    Last Post: 09-15-2011, 11:56 AM
  2. just stop working when compile...
    By notcodemonkey in forum C Programming
    Replies: 27
    Last Post: 10-13-2010, 01:21 PM
  3. Creating a window causes a trackbar to stop working?
    By kidburla in forum Windows Programming
    Replies: 2
    Last Post: 09-20-2007, 05:44 AM
  4. gameports stop working
    By tyler4588 in forum Tech Board
    Replies: 3
    Last Post: 05-26-2005, 10:38 AM
  5. keyboard stop working at Dos
    By arian in forum C++ Programming
    Replies: 1
    Last Post: 11-18-2004, 02:32 PM