I am sorry I know I opened some topic about this before , but I finall used strpbrk with a correct form , tell me if I have bad codes which works slowly.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct content {
char name[30];
} X;
void sirala(X *,int,int *);
int main()
{
X liste[10];
FILE *fp;
int puanlar[30];
int x=0;
int i=0;
char *a;
if((fp=fopen("d.txt","r"))==NULL) {
perror("d.txt");
return 0; }
else {
while(fgets(liste[i].name,30,fp)!=NULL) {
a=strpbrk(liste[i].name,"0123456789");
sscanf(a,"%d",&puanlar[i]);
i++;
x+=1;
}
sirala(liste,x,puanlar);
fclose(fp);
}
if((fp=fopen("sonuc.txt","w"))==NULL) {
perror("sonuc.txt");
return 0; }
else {
for(i=0;i<x+1;i++){
fprintf(fp,"%s",liste[i].name);
if(i==3) fprintf(fp,"\n");}}
return 0;
}
void sirala(X *kayit,int kont,int *not) {
int tur,say,tut;
X gecici;
for(tur=0;tur<kont;tur++) {
for(say=0;say<kont;say++) {
if(not[say]<not[say+1]) {
gecici=kayit[say];
kayit[say]=kayit[say+1];
kayit[say+1]=gecici;
tut=not[say];
not[say]=not[say+1];
not[say+1]=tut; } } }
}
There is one thing I dont understand which I want to know why :
If dont use this code line :
if(i==3) fprintf(fp,"\n");} }
When writing the third name it does not make \n while it makes new line writing the names and grades. I hope I asked my question clearly. Thank you.