Like Tree2Likes
  • 2 Post By grumpy

why stop working?

This is a discussion on why stop working? within the C Programming forums, part of the General Programming Boards category; 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 ...

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

    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 03:58 AM.

  2. #2
    ZuK
    ZuK is offline
    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
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,473
    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
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  4. #4
    Registered User
    Join Date
    Oct 2013
    Location
    greece
    Posts
    31
    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
    31
    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,208
    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.
    Hodor and rogster001 like this.
    Right 98% of the time, and don't care about the other 3%.

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, 01:32 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21