사실 아까 그 scheme.GO.data 분석하는 과제 아직도 이해 안됨
밍고스사랑해(mingosudaisuki)
2016-04-14 21:39
추천 0
원하는게 이런 동작임?
http://codepad.org/MVR2G9Ks
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char **argv)
{
if(argc != 2)
{
return 0;
}
FILE *fp = fopen(argv[1], "r");
if(!fp)
{
return 0;
}
long *arr = malloc(sizeof(long) * 10000000), n = 0, cnt = 0, buf = 0, c;
if(!arr)
{
return 0;
}
memset(arr, 0, sizeof(long) * 10000000);
printf("Reading ");
puts(argv[1]);
while((c = fgetc(fp)) >= 0)
{
if(c >= '0' && c <= '9')
{
buf = buf * 10 + c - '0';
++cnt;
}
else if(c == '\t')
{
if(cnt == 7)
{
if(!arr[buf])
{
++n;
}
++arr[buf];
}
cnt = buf = 0;
}
else if(c == '\n')
{
cnt = buf = 0;
}
else
{
cnt = 8;
continue;
}
}
printf("Total number of GOs : %ld\n", n);
while(1)
{
printf("Enter GO to find : ");
scanf("%ld", &buf);
if(buf < 0 || buf >= 10000000)
{
break;
}
printf("%ld GO:ld were found.\n", arr[buf], buf);
}
free(arr);
fclose(fp);
return 0;
}
항목 하나씩 동적할당해서 이어줘야겠죠
아니 대체 왜?
출제자가 malloc을 쓰라고 했으니 동적 배열을 원하는 것도 아니고 명시적인 언급이 없으니 linked list를 원하는 것도 아니고 각 줄의 마지막에 있는 문자열 필드는 그냥 무시하면 되고 줄의 배치를 생각해야 하는 것도 아닌데
histogram count 를 쓰면 젤 편하지만 의도가 뭘라나~
자릿수 만큼 전역이면 malloc 도 초기화도 쓸 필요도 없으니깐 괜히 힘들게 하라는건 아닐것 같은데
레거시 플랫폼들이 기본 스택 크기를 얼마나 준다고 그런 소리를 하냐?
잠깐만 근데 너 지금 전역이라고 했냐
ㅇㅇ
전 미필입니다만?