Like Tree2Likes
  • 2 Post By Salem

Need help with Dev C++

This is a discussion on Need help with Dev C++ within the C Programming forums, part of the General Programming Boards category; Hi All, I'm new to this forum. I recently started coding in C. I've tried two IDE's - CodeBlocks and ...

  1. #1
    Registered User
    Join Date
    May 2012
    Location
    India
    Posts
    32

    Need help with Dev C++

    Hi All, I'm new to this forum. I recently started coding in C. I've tried two IDE's - CodeBlocks and DevC++.

    But I get some kind of an error which am not able to resolve.

    Here's a screen shot of the same.

    Name:  error.jpg
Views: 159
Size:  55.6 KB

    And this is the the simple code that am trying to execute:

    Code:
    #include<stdio.h>
    #include<conio.h>
    int main(void)
    {
        int a[50];
        int i;
        for(i = 0 ; i < 10 ; i++)
        {
              char next;
              scanf("%d", &a[i]);
              printf("Got more?");
              scanf("%c", next);
              if(next == 'y')
                    continue;
              else
                    break;
        }
        printf("Count = %d", i);
        getch();
        return 0;
    }
    Anyone knows how to resolve this?

    Thanks in advance.

  2. #2
    a_capitalist_story
    Join Date
    Dec 2007
    Posts
    2,641
    Code:
    scanf("%d", &a[i]);
    printf("Got more?");
    scanf("%c", next);
    Compare the two scanf lines.

    Also

  3. #3
    Registered User
    Join Date
    May 2012
    Location
    India
    Posts
    32
    Quote Originally Posted by rags_to_riches View Post
    Code:
    scanf("%d", &a[i]);
    printf("Got more?");
    scanf("%c", next);
    Compare the two scanf lines.

    Also
    "rags_to_riches", thanks for taking time out to answer my question.

    But the code that you've written is the same as I posted???

  4. #4
    Registered User
    Join Date
    Dec 2011
    Posts
    795
    > But the code that you've written is the same as I posted???
    Obviously, he's asking you to look closer and see the error.

  5. #5
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,340
    > But the code that you've written is the same as I posted???
    Yes, but one of those lines is wrong.
    rags_to_riches asked you to compare the two lines, and try to figure out what is wrong.

    Here's another hint - enable more warnings for your compiler (this probably only works in code::blocks)
    Code:
    $ gcc -Wall bar.c
    bar.c: In function ‘main’:
    bar.c:12: warning: format ‘%c’ expects type ‘char *’, but argument 2 has type ‘int’
    bar.c:12: warning: ‘next’ may be used uninitialized in this function
    stahta01 and antred like this.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  6. #6
    Registered User
    Join Date
    May 2012
    Location
    India
    Posts
    32
    Quote Originally Posted by Salem View Post
    > But the code that you've written is the same as I posted???
    Yes, but one of those lines is wrong.
    rags_to_riches asked you to compare the two lines, and try to figure out what is wrong.

    Here's another hint - enable more warnings for your compiler (this probably only works in code::blocks)
    Code:
    $ gcc -Wall bar.c
    bar.c: In function ‘main’:
    bar.c:12: warning: format ‘%c’ expects type ‘char *’, but argument 2 has type ‘int’
    bar.c:12: warning: ‘next’ may be used uninitialized in this function
    Thanks mate, i resolved the previous issue.

    I'm writing this program to scan an array of integers, but doesn't seem to work properly.

    Here's the code:

    Code:
    #include<stdio.h>
    #include<conio.h>
    int main(void)
    {
        int a[50];
        int i;
        for(i = 0 ; i < 10 ; i++)
        {
              char next;
              scanf("%d", &a[i]);
              printf("Got more?");
              scanf("%s", &next);
              if(next == 'y')
                    continue;
              else
                    break;
        }
        printf("Count = %d", i);
        getch();
        return 0;
    }
    The list does scan numbers, but the count value displayed at the end is incorrect.

    Can someone help me with this?

    Thanks in advance.

  7. #7
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,340
    How many bytes will %s write to the char pointer you passed in?

    Answer - at least TWO

    Is there room for two characters in your code?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  8. #8
    Registered User claudiu's Avatar
    Join Date
    Feb 2010
    Location
    London, United Kingdom
    Posts
    2,094
    Also, drop Dev C++ and use an IDE that hasn't been abandoned for years.
    1. Get rid of gets(). Never ever ever use it again. Replace it with fgets() and use that instead.
    2. Get rid of void main and replace it with int main(void) and return 0 at the end of the function.
    3. Get rid of conio.h and other antiquated DOS crap headers.
    4. Don't cast the return value of malloc, even if you always always always make sure that stdlib.h is included.

  9. #9
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Location
    Cambridge, UK
    Posts
    1,682
    Its sad Dev-C++ is dying! Or perhaps dead! I use to love thew IDE.

    ssharish
    Life is like riding a bicycle. To keep your balance you must keep moving - Einstein

  10. #10
    Registered User claudiu's Avatar
    Join Date
    Feb 2010
    Location
    London, United Kingdom
    Posts
    2,094
    I never loved it because it was full of bugs, even during the prime of its time.
    1. Get rid of gets(). Never ever ever use it again. Replace it with fgets() and use that instead.
    2. Get rid of void main and replace it with int main(void) and return 0 at the end of the function.
    3. Get rid of conio.h and other antiquated DOS crap headers.
    4. Don't cast the return value of malloc, even if you always always always make sure that stdlib.h is included.

  11. #11
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Location
    Cambridge, UK
    Posts
    1,682
    I used to use it just for the IDE. Never use to compile anything on it tho. Occasionally still use the IDE. Altho I agree there are better IDE like Code::Block.
    It was very useful to write sample codes to test certain bit while developing a huge project. And also I found it quite useful with contrast to other IDE, that u need a project file even to develop a simple code.

    I like the clt+N -> new file -> compile thing on Dev-C++. And not to worry about creating project and the other stuff.

    Perhaps this is still available feature on other IDE which I might haven’t discovered to its complete extent.

    ssharish
    Life is like riding a bicycle. To keep your balance you must keep moving - Einstein

  12. #12
    Registered User manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    Kolkata@India
    Posts
    2,490
    Quote Originally Posted by ssharish2005 View Post
    Perhaps this is still available feature on other IDE which I might haven’t discovered to its complete extent.
    Code::Blocks does that too...to a certain extent.
    Ctrl+N will give a text file.. but if you create or open a .cpp or .c file, you can compile that directly, without bothering with a project.
    Manasij Mukherjee | gcc-4.8.2 @Arch Linux
    Slow and Steady wins the race... if and only if :
    1.None of the other participants are fast and steady.
    2.The fast and unsteady suddenly falls asleep while running !



  13. #13
    Registered User claudiu's Avatar
    Join Date
    Feb 2010
    Location
    London, United Kingdom
    Posts
    2,094
    I agree with manasij, in fact, I use Code::Blocks all the time for quick "one-file-builds" usually to test code posted by people on this forum.
    1. Get rid of gets(). Never ever ever use it again. Replace it with fgets() and use that instead.
    2. Get rid of void main and replace it with int main(void) and return 0 at the end of the function.
    3. Get rid of conio.h and other antiquated DOS crap headers.
    4. Don't cast the return value of malloc, even if you always always always make sure that stdlib.h is included.

  14. #14
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,340
    dev-c++ has been reborn -> Orwell Dev-C++ | Free Development software downloads at SourceForge.net
    I've no idea how many IDE bugs have been fixed, or what new features it offers, but at least it is using a much newer version of GCC.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  15. #15
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Location
    Cambridge, UK
    Posts
    1,682
    Quote Originally Posted by Salem View Post
    dev-c++ has been reborn -> Orwell Dev-C++ | Free Development software downloads at SourceForge.net
    I've no idea how many IDE bugs have been fixed, or what new features it offers, but at least it is using a much newer version of GCC.
    Happy days!
    Life is like riding a bicycle. To keep your balance you must keep moving - Einstein

Popular pages Recent additions subscribe to a feed

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