Hi
I have done the whole code it works fine except for some really wierd symbols that get displayed when I exceute. I have gone through it with a fine toothed comb but cannot find the issue, maybe someone can just point it to me if u see whats the issue
Following I the .txt file it is supposed to read and then the code and after the code am pasting the wierd display with the symbols
PHP Code:
Darwin,3,33
Darwin,1,11
Darwin,6,66
Darwin,4,44
Darwin,5,55
Brisbane,2,222
Brisbane,1,111
Brisbane,6,666
Brisbane,3,333
Sydney,1,101
Sydney,2,202
Sydney,3,303
Sydney,6,606
Sydney,5,505
Sydney,4,404
Perth,3,313
Perth,4,414
Perth,5,515
Code:
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<ctype.h>
void main()
{
char str[80],str1[80];
int n,i,j,temp,acc[100],indexes[100];
char index,*p;
FILE *fp,*fw;
fw=fopen("index.txt","w");
printf("\n How many records do you want : ");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("\n Enter account number : ");
scanf("%d",&acc[i]);
}
i=0;
while(i<n)
{
index='0';
fp=fopen("Accounts.txt","r");
if(fp==NULL)
{
printf("\n file does not exist");
exit(-1);
}
if(fw==NULL)
{
printf("\n file does not exist");
exit(-1);
}
printf(" i = %d \n ",i);
while(fgets(str,79,fp)!=NULL)
{
printf("account = %d and index =%c \n ",acc[i],index);
p = strtok(str, "\t");
p=strtok(NULL,"\t");
printf("atoi = %d \n",atoi(p));
if(atoi(p)==acc[i])
{
printf("index = %c , account = %s\n",index, p);
fputc(index,fw);
fputc('\n',fw);
break;
}
index++;
}
i++;
fclose(fp);
}
fclose(fw);
fp=fopen("index.txt","r");
i=0;
// sort index file
while(fgets(str,79,fp)!=NULL)
{
indexes[i]=atoi(str);
printf("index[i]= %d",indexes[i]);
i++;
}
fclose(fp);
for(i=0;i<n;i++)
{
for(j=0;j<(n-i-1);j++)
{
if(indexes[j]>indexes[j+1])
{
temp=indexes[j];
indexes[j]=indexes[j+1];
indexes[j+1]=temp;
}
}
}
i=0;
fp=fopen("index.txt","w");
while(i<n)
{
index=indexes[i]+'0';
printf("\n index[i]= %c",index);
fputc(index,fp);
fputc('\n',fp);
i++;
}
fclose(fp);
fp=fopen("index.txt","r");
printf("\n\n output - \n ");
while(fgets(str,79,fp)!=NULL)
{
printf("\n str= %s",str);
i=atoi(str);
j=0;
fw=fopen("Accounts.txt","r");
while(fgets(str1,79,fw)!=NULL)
{
if(i==j)
{
printf("\n %s ",str1);
break;
}
j++;
}
fclose(fw);
}
fclose(fp);
scanf("%*c");
}
PHP Code:
City Jan Feb Mar Apr May Jun
Darwin═════
Brisbane═══
Sydney═════
Perth══════
Perth═════,
Perth══════²²²²½½½½½½½½ 11 0 33 44 55 66
Brisbane═══
Sydney═════
Perth══════
Perth═════,
Perth══════²²²²½½½½½½½½ 111 222 333 0 0 666
Sydney═════
Perth══════
Perth═════,
Perth══════²²²²½½½½½½½½ 101 202 303 404 505 606
Perth══════
Perth═════,
Perth══════²²²²½½½½½½½½ 0 0 313 0 0 0
can someone pls tell me where I am wrong?