# include<stdio.h>
# include<conio.h>
void main()
{
    int s1[10],s2[10],s3[10],total[10],per[10],i;
    char name[20],pid[10];
    clrscr();
    printf("==================== Marksheet ======================");
    printf("\n\n\n");
    for(i=0;i<3;i++)
    {
        printf("\n Enter your name:");
        scanf("%s",name[i]);
        printf("\n Enter your PID:");
        scanf("%s",pid[i]);
        printf("\n Enter your Subject1:");
        scanf("%d",&s1[i]);
        printf("\n Enter your Subject2:");
        scanf("%d",&s2[i]);
        printf("\n Enter your Subject3:");
        scanf("%d",&s3[i]);
    }
    printf(" \n ===================== RESULT OF MARKSHEET =================");
    for(i=0;i<3;i++)
    {
        printf("\n Your name is:%s",name[i]);
        printf("\n Your PID is:%s",pid[i]);
        printf("\n Your Subject1 marks is:%d",s1[i]);
        printf("\n Your Subject2 marks is:%d",s2[i]);
        printf("\n Your Subject3 marks is:%d",s3[i]);
        printf("\n Your Total of Marks is:%d",s1[i]+s2[i]+s3[i]);
        printf("\n Your Percentage is:%d",total[i]/3);
    }
    getch();
}

This bold code gives me null value....plz help me out of this
and also taking some null exception in char array of name & pid.....plz help me out.

Recommended Answers

All 9 Replies

Line number 13 and 15: you have missed an "&"
See scanf

Also, there are some other things i would like to mention:

1) # include<conio.h> --> Not standard C header

2) void main() --> Should be int main

3) clrscr(); and getch(); : Again, not standard.

You can't read a string (%s) into a single char (name[i] and pid[i]). You need to define them both as 2D arrays,
names[Number of names][number of chars for each name]

change your lines 5,6 as below:
int s1[3],s2[3],s3[3],total[3],per[3],i; char name[3][20],pid[3][10];

and change line 31 as below:
printf("\n Your Total of Marks is:%d",(total[i]=s1[i]+s2[i]+s3[i]));

Line number 13 and 15: you have missed an "&"
See scanf

Also, there are some other things i would like to mention:

1) # include<conio.h> --> Not standard C header

2) void main() --> Should be int main

3) clrscr(); and getch(); : Again, not standard.

myk45 conio.h is header file of Turbo C and Borland C++. clrscr() and getch() also is in conio.h. Just FYI.

We know. That doesn't alter the fact that it's non-standard and should not be used.

We know. That doesn't alter the fact that it's non-standard and should not be used.

standart for what? Every compiler have own standart. some of them also compatible with ANSI but they have own libraries. Like Microsoft, Borland, Watcom,.....

standart for what?

The standard for the C language, which tells us what to expect from a conforming implementation.

Every compiler have own standart.

Those aren't standards, they're specific implementations.

some of them also compatible with ANSI but they have own libraries. Like Microsoft, Borland, Watcom,.....

These days all implementations ought to be compatible with the C standard. They will also provide their own library extensions. The extensions are usually not portable, which is why a standard library function is preferred, if available.

Older implementations may support non-standard features such as void main(), but there's no good reason to persist in using such features unless you're forced into using an old implementation that doesn't support the standard, i.e. for very old legacy code or if you're on a course that only provides an old, non-conforming implementation.

These days all implementations ought to be compatible with the C standard.

That's where it gets tricky. There are four versions of the C standard at present:

  1. C90: The first official standard from ISO in 1990. All relatively modern compilers claiming to be C compilers should (and will likely) conform to this one.
  2. C95: C95 isn't really a full revision, it's C90 with normative addendum 1 from 1995. All modern compilers should (and will likely) include normative addendum 1 and thus support C95.
  3. C99: The second revision of the standard in 1999. Most compilers will not support this standard, or will only support it piecemeal.
  4. C11: The most recent standard from late 2011. C99 compilers are quickly moving to support C11, if they don't already, but non-C99 compilers aren't likely to in the near future.

If you're writing portable code, it's probably best to assume at most C95. Or you can take the perspective of "if it's standard, it's portable", and let consumers of the code find a conforming compiler.

And on a side note, Turbo C doesn't fully support even C90. ;)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.