#include <stdio.h>
#include <stdlib.h>
struct tool{
int record;
char tool_n[50];
int quant;
float cost;
};
typedef struct tool tool;
void che(tool a[]){
int i=0;
scanf("%d%s%d%f",&a[i].record, a[i].tool_n, &a[i].quant, &a[i].cost);
}
int main(){
char *fn = "hardware.dat";
tool num[100];
int i=0,count=0;
FILE *po;
if ((po = fopen(fn, "r")) == NULL){
printf("Error ");
exit(1);
}
//while (i != 0){
// fscanf(po, "%d %s %d %f",num[count]);
//}
che(&num[count]);
//scanf("%s",num[count].tool_n);
printf("%d %s %d %f ", num[count].record, num[count].tool_n, num[count].quant, num[count].cost);
scanf(" %d",&i);
if (i == 99){
if ((po = fopen(fn, "w")) == NULL){
printf("Error ");
exit(1);
}
}
fclose(po);
return 0;
}
여기서 tool구조체 포인터변수로 쓴 void함수를 쓰고 싶은데
che(num[count])가 어떻게 해도 동작할 기미가 안보임ㄷㄷ
che(&num[count])로 해도 안되고 che(*num[count])로 해도 안됨; 이거 뭐 어케해야 동작하나여
근데 저대로 한다고 했을때 포인터로 제대로 동작은하나염 ㅡㅡ;
//
시그너처 검색해봐서 뭔진 알았어요. 그래서 대략 저렇게 바꿔봤는데 그래도 결과값이 이상하게 나옴ㄷㄷ
c언어 왜케 이상함 ㄷㄷㄷ
//
뒤에 뻘짓해서 네번째 tool_n을 cost로 바꿨는데 이젠 실행도 안됨ㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋ
시그너처 선언을 잘못햇어
저기에 포이터를 이상하게 박았네여 ㅈㅅ 암튼 댓글횽 감사여 ㅠㅠ
che(tool*a)가 되어야 하지 않을까ㅡ근데 이 코드의 내용은 뭐지
과젠데 배열섞은 포인터 섞은 스트럭쳐가 개헷갈려서 함 해봤어염 ㅠㅠ;