#include <stdio.h>
main(){
int ctr, ctr2, accn, tempn;
char name[10][20], kwh[10][5], due[10][5], paid[10][5], tempne[20], tempkwh[5], tempdue[5], temppd[5];
clrscr();
for(ctr=0;ctr<10;ctr++){
clrscr();
printf("Account number:\n");
scanf("%d",&accn[ctr]);
printf("Name:\n");
scanf("%s",&name[ctr][0]);
printf("KWH used:\n");
scanf("%s",&kwh[ctr][0]);
printf("Amount due:\n");
scanf("%s",&due[ctr][0]);
printf("Amount paid:\n");
scanf("%s",&paid[ctr][0]);
}
ctr=1;
for( ;ctr==1; ){
ctr=0;
for(ctr2=0;ctr2<10;ctr2++){
if(accn[ctr]>accn[ctr+1])
{
tempn=accn[ctr];
accn=accn[ctr+1];
accn[ctr+1]=tempn;
tempne=name[ctr];
name[ctr]=name[ctr+1];
name[ctr+1]=tempne;
tempkwh=kwh[ctr];
kwh[ctr]=kwh[ctr+1];
kwh[ctr+1]=tempkwh;
tempdue=due[ctr];
due[ctr]=due[ctr+1];
due[ctr+1]=tempdue;
temppd=paid[ctr];
paid[ctr]=paid[ctr+1];
paid[ctr+1]=temppd;
ctr=1;
}
}
}
clrscr();
ctr=0;
for( ;ctr<10;ctr++){
printf("%d %s \n%s\n %s\n %s\n\n",accn[ctr], name[ctr], kwh[ctr], due[ctr], paid[ctr]);
}
}
Asked
Active
Viewed 54 times
0

Luchian Grigore
- 253,575
- 64
- 457
- 625

yambooo
- 1
-
Could you show where in this code dump the error is occurring? – Will Jan 16 '13 at 13:44
-
This is tagged as C++ but the code looks more like C. It’s certainly not valid C++ code (but even in C it’s deprecated). – Konrad Rudolph Jan 16 '13 at 13:52
1 Answers
1
First one that pops out is:
scanf("%d",&accn[ctr]);
where accn
and ctr
are both of type int
. What's it supposed to do?
Also
tempn=accn[ctr];
where tempn
is an array.
I'm afraid the solution to your problem can only be found here.

Community
- 1
- 1

Luchian Grigore
- 253,575
- 64
- 457
- 625