ตามหัวข้อเลยครับ ถ้า Run ใน dev-c++ ปกติก็ไม่อะไรนะครับ
แต่รันในเว็บส่งแลปอาจารย์ (autogradr) แล้วก็ขึ้นตามหัวข้อเลยครับ ลองดูตามที่มันบอกแล้วแก้แล้ว
ลองเลื่อนแล้วก็ไม่เปลี่ยนนะครับ เลยไม่เข้าใจว่าเกิดจากอะไร จากนั้นก็แก้ไม่ถูกเลยครับ T-T
โค้ดมีตามที่นี้ครับ ส่วนอีกอันโค้ด txt ครับ
[Spoil] คลิกเพื่อดูข้อความที่ซ่อนไว้#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct INPUT {
char num[20] ;
char name[20] ;
char date[20] ;
};//end struct
//main function
int main() {
FILE *A = fopen( "a.txt","r" );
struct INPUT i[20] ;
int count = 0 , x = 0 ;
for( x = 0 ; fscanf( A , "%s %s %s" , &i[x].num , &i[x].name , &i[x].date ) != EOF ; x++ ) {
if( strcmp( i[x].num , "No" ) == 0 ) {
x-- ;
continue ;
}//end if
else count++ ;
}//end for
int DATE[count] ;
int Years [count] ,Y [count] ;
int Months[count] ,M [count] ;
int Days [count] ,D [count] ;
for( x = 0 ; x < count ; x++ ) {
char *delim = "-" ;
char *copy ;
int count_loop = 0 ;
Years [x] = 0 ,Y [x] = 0;
Months[x] = 0 ,M [x] = 0;
Days [x] = 0 ,D [x] = 0;
copy = strtok(i[x].date,delim);
DATE[x] = atoi(copy);
while( copy != NULL ) {
if( count_loop == 0 ) Years[x] = DATE[x] ; //end if
else if( count_loop == 1 ) Months[x] = DATE[x] ; //end else if
else if( count_loop == 2 ) Days[x] = DATE[x] ; //end else if
copy = strtok(NULL,delim);
DATE[x] = atoi(copy);
count_loop++ ;
}//end while
Years[x] =2017-Years[x] ;
Years[x]*=360 ;
Months[x]*=30 ;
int date = Years[x] + Months[x] + Days[x] ;
date-=201 ;
//START Count Days/Months/Years
while( date >= 360 ) {
date-=360;
Y[x]++ ;
}//end while
while( date >= 30 ) {
date-=30;
M[x]++ ;
}//end while
while( date != 0 ) {
date-- ;
D[x]++ ;
}//end while
//END Count Days/Months/Years
//START loop answer TC
if(M[x] == 4) {
M[x]+=3 ;
}//end else if
else if(M[x] == 5) {
M[x]++;
}//end else if
else if(M[x] == 7) {
Y[x]+=2;
M[x]-=3;
}//end else if
else if(M[x] == 8) {
Y[x]+=2;
M[x]-=5;
}//end else if
else if(M[x] == 9) {
Y[x]+=2;
M[x]-=7;
}//end else if
else if(M[x] == 10) {
Y[x]+=2;
M[x]-=9;
}//end else if
if(M[x] == 11) {
Y[x]+=2 ;
M[x]-=11 ;
}//end else if
//END loop answer TC
}//end for
//display
for( x = 0 ; x < count ; x++ ) {
printf("%s %d Years, %d Months",i[x].name ,Y[x] ,M[x] );
if( x != count - 1 ) printf( "\n" );//end if
}//end for
fclose(A);
return 0;
}//end function
[Spoil] คลิกเพื่อดูข้อความที่ซ่อนไว้Name Age Salary(Bath) Job
Pong 32 45000 Programmer
Som 25 23000 Support
Aoy 24 33250 Advisor
Ying 26 34550 Programmer
Yot 28 50000 Founder
Pot 31 24500 HR
Vip 25 25450 Programmer
ภาษา C ขึ้น run.sh: line 5: 15 Segmentation fault (core dumped) ./a.out $@
แต่รันในเว็บส่งแลปอาจารย์ (autogradr) แล้วก็ขึ้นตามหัวข้อเลยครับ ลองดูตามที่มันบอกแล้วแก้แล้ว
ลองเลื่อนแล้วก็ไม่เปลี่ยนนะครับ เลยไม่เข้าใจว่าเกิดจากอะไร จากนั้นก็แก้ไม่ถูกเลยครับ T-T
โค้ดมีตามที่นี้ครับ ส่วนอีกอันโค้ด txt ครับ
[Spoil] คลิกเพื่อดูข้อความที่ซ่อนไว้
[Spoil] คลิกเพื่อดูข้อความที่ซ่อนไว้