need help to edit

This is a discussion on need help to edit within the C Programming forums, part of the General Programming Boards category; hi i have a program that is supposed to put in the number of student and marks and printf them ...

  1. #1
    Registered User
    Join Date
    Feb 2010
    Posts
    96

    need help to edit

    hi i have a program that is supposed to put in the number of student and marks and printf them out on the screen. this is not working can somone tell me what i did wrong
    Code:
    #include<stdio.h>
    #include<conio.h>
    #include<stdlib.h>
    
    main()
    {
          char student[2][9];
          float marks[2][3];
          int numb,i,j;
          
          
          printf("how many student");
          scanf("%d",&numb);     
          
          for(i=0;i<numb;i++)
          {
          printf("student name");
          scanf("%s",&student);     
         
                   for(j=0;j<5;j++)
                {
                printf("enter the mark");
                scanf("%i",&marks[i][j]);  
                }     
          }
          
         printf("%\n\n", "Student", "PRG", "DGS", " MTH", " ECR", " GED");
         for (i = 0; i < numb; i++) {
         printf("%s", student[i]);
    
          for (j = 0; j < 5; j++) {
           printf("%d ", marks[i][j]);
          }
           printf("\n");
         }       
          getch();
          
    }

  2. #2
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    Code:
    printf("%\n\n", "Student", "PRG", "DGS", " MTH", " ECR", " GED");
    This isn't right - the format string should have a %s for each string you want to insert into the output.

    I also suspect you're having a problem with your array bounds - you declare marks[2][3], but there are times in your loops when second index can increase up to 5.

    Also - you might consider posting the actual output and how it is different from what you expected - it makes it a lot easier for us to pinpoint the biggest problems.

    edit: Just wanted to point out that conio.h and getch() are not standard C - they just happen to be provided by your compiler. There's nothing wrong with using them when you're learning C - but I just think it's important to know what's standard and what isn't.

  3. #3
    Registered User
    Join Date
    Feb 2010
    Posts
    96
    someonme help me

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,529
    > for(j=0;j<5;j++)
    How big is your array?

    > scanf("%i",&marks[i][j]);
    What is the correct format for reading floats?
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. (Multiline) Edit Control Limit
    By P4R4N01D in forum Windows Programming
    Replies: 9
    Last Post: 05-17-2008, 11:56 AM
  2. line number on a rich edit control
    By rakan in forum Windows Programming
    Replies: 1
    Last Post: 02-18-2008, 06:58 AM
  3. WS_HSCROLL in ES_READONLY edit box error
    By Homunculus in forum Windows Programming
    Replies: 4
    Last Post: 02-13-2006, 07:46 AM
  4. Multiline Edit Box Parser
    By The Brain in forum Windows Programming
    Replies: 6
    Last Post: 11-01-2005, 06:15 PM
  5. Replies: 3
    Last Post: 07-23-2005, 08:00 AM

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