alexa-tracking

Main Content

1024
1024
KASKUS
51
244
https://www.kaskus.co.id/thread/52c64b93a4cb176d188b461c/edit-isi-text-di-notepad-dengan-c
edit isi text di notepad dengan C
gan ada yang tau ini eror dmna ya gan


Quote:#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef struct
{
char *name;
float gpa;
}student;

int main()
{
FILE *originalFile = fopen("C:\\Users\\jurs\\Desktop\\students.txt","r");
FILE *newFile = fopen("C:\\Users\\jurs\\Desktop\\students_temp.txt","w");

int studentCount;
fscanf(originalFile, "%i", &studentCount);

student *passingStudents = malloc(sizeof(student) * studentCount);

int passingCount = 0;
for(int i = 0; < studentCount, i++);
{
int namelen;

fscanf(originalFile, "%i", &nameLen);

char *name = malloc(sizeof(char) * (nameLen + 1));
name[nameLen] = '\0';
float gpa;

fscanf(originalFile, "%s %f", name, &gpa);

if (gpa >=65.0)
{
passingStudents[passingCount].name = name;
passingStudents[passingCount].gpa = gpa;

passingCount++;"C:\\Users\\jurs\\Desktop\\students.txt"
}
}

fprintf(newFile, "%i\n",passingCount);

for (int i = 0; i < passingCount; i++)
fprintf(newFile, "%i %s %.2f\n", strlen(passingStudents[i].name, pasiingStudents[i].gpa));



fclose(originalFile);
fclose(newFile);

remove("C:\\Users\\jurs\\Desktop\\students.txt");
rename("C:\\Users\\jurs\\Desktop\\students_temp.txt" , "C:\\Users\\jurs\\Desktop\\students.txt");

printf("berhasil menghapus semua failing Students.")
return 0;
}




kalau di dev C nya di tandain yang ini gan

Quote:for(int i = 0; < studentCount; i++);


di bantu ya gan
Coba begini gan
Code:

int i = 0;
for(i = 0; < studentCount; i++) // ; ada titik koma gan
{


di C belum support jika deklar variabel di for.

EDIT: ternyata ada titik koma dibelakangnya emoticon-Ngakak (S)
Quote:Original Posted By krofz
Coba begini gan
Code:

int i = 0;
for(i = 0; < studentCount; i++) // ; ada titik koma gan
{


di C belum support jika deklar variabel di for.

EDIT: ternyata ada titik koma dibelakangnya emoticon-Ngakak (S)


udah di hapus gan tapi tetap gak jalan emoticon-Bingung (S)

Quote:Original Posted By krofz
Coba begini gan
Code:

int i = 0;
for(i = 0; < studentCount; i++) // ; ada titik koma gan
{


di C belum support jika deklar variabel di for.

EDIT: ternyata ada titik koma dibelakangnya emoticon-Ngakak (S)



udah saya gan ti jadi gini gan tapi tetap erorr
Quote: int passingCount;
for (int i = 0; i < studentCount; i++)
{
int namelen;

fscanf(originalFile, "%i", &nameLen);

char *name = malloc(sizeof(char) * (nameLen + 1));
name[nameLen] = '\0';
float gpa;


tapi tetap erorr gan

erorrnya di
Code:
fscanf(originalFile, "%i", &nameLen);
pesen errornya apa gan?
Quote:Original Posted By BreakMyFall
pesen errornya apa gan?



pesan erorrnya ini gan

Code:
C:\Users\jurs\Desktop\tugas.c||In function `main':|
C:\Users\jurs\Desktop\tugas.c|22|error: 'for' loop initial declaration used outside C99 mode|
C:\Users\jurs\Desktop\tugas.c|26|error: `nameLen' undeclared (first use in this function)|
C:\Users\jurs\Desktop\tugas.c|26|error: (Each undeclared identifier is reported only once|
C:\Users\jurs\Desktop\tugas.c|26|error: for each function it appears in.)|
C:\Users\jurs\Desktop\tugas.c|45|error: redefinition of 'i'|
C:\Users\jurs\Desktop\tugas.c|22|error: previous definition of 'i' was here|
C:\Users\jurs\Desktop\tugas.c|45|error: 'for' loop initial declaration used outside C99 mode|
C:\Users\jurs\Desktop\tugas.c|46|error: `pasiingStudents' undeclared (first use in this function)|
C:\Users\jurs\Desktop\tugas.c|46|error: too many arguments to function `strlen'|
C:\Users\jurs\Desktop\tugas.c|57|error: syntax error before "return"|
||=== Build finished: 10 errors, 0 warnings (0 minutes, 1 seconds) ===|

agan nulisnya nameLen
itu deklarasinya namelen
Quote:Original Posted By BreakMyFall
agan nulisnya nameLen
itu deklarasinya namelen


oh ia gan

tapi masih error di sini gan
Code:
for ( int i = 0; i < studentCount; i++)
Quote:Original Posted By jujurss


oh ia gan

tapi masih error di sini gan
Code:
for ( int i = 0; i < studentCount; i++)


Code:

int i;
for (i = 0; i < studentCount; i++)


kalo C nggak bisa naruh deklarasi counter di dalem for gan
Quote:Original Posted By BreakMyFall


Code:

int i;
for (i = 0; i < studentCount; i++)


kalo C nggak bisa naruh deklarasi counter di dalem for gan


wah jadi ane harus deklarasi dmna gan
saya masih newbie gan

Quote:Original Posted By jujurss


wah jadi ane harus deklarasi dmna gan
saya masih newbie gan



ya itu udah ane bantuin nulis deklarasinya emoticon-Malu (S)
Quote:Original Posted By BreakMyFall


ya itu udah ane bantuin nulis deklarasinya emoticon-Malu (S)


oh ia gan emoticon-Toast

terus erorr disini lagi gan

Code:
fprintf(newFile, "%i %s %.2f\n", strlen(passingStudents[i].name, passingStudents[i].name, passingStudents[i].gpa));



erorr compilenya ini gan

Code:
C:\Users\jurs\Desktop\tugas.c||In function `main':|
C:\Users\jurs\Desktop\tugas.c|47|error: too many arguments to function `strlen'|
||=== Build finished: 1 errors, 0 warnings (0 minutes, 2 seconds) ===|
Quote:Original Posted By jujurss


oh ia gan emoticon-Toast

terus erorr disini lagi gan

Code:
fprintf(newFile, "%i %s %.2f\n", strlen(passingStudents[i].name, passingStudents[i].name, passingStudents[i].gpa));



erorr compilenya ini gan

Code:
C:\Users\jurs\Desktop\tugas.c||In function `main':|
C:\Users\jurs\Desktop\tugas.c|47|error: too many arguments to function `strlen'|
||=== Build finished: 1 errors, 0 warnings (0 minutes, 2 seconds) ===|


itu agan ngapain pake strlen gan?
tinggalin jejak dulu gan