도움을 주셔서 감사합니다 ...하지만 여전히 화면에 300,400을 인쇄하지 않습니다. 아래는 내 fullcode입니다 : 파일 [file contain : S (300,400)]이 commandprompt에서 전달되고 S, 첫 번째 괄호, 쉼표 또는 마지막 닫는 대괄호를 읽지 않고 두 개의 값을 읽습니다.scanf로 대괄호를 건너 뛰는 방법
#include <stdio.h>
int a;
int b;
int main (int argc, char *argv[])
{
if (argc != 2) /* argc should be 2 for correct execution */
{
/* We print argv[0] assuming it is the program name */
printf("usage: %s filename", argv[0]);
}
else
{
// We assume argv[1] is a filename to open
FILE *file = fopen(argv[1], "r");
/* fopen returns 0, the NULL pointer, on failure */
if (file == 0)
{
printf("Could not open file\n");
}
else
{
/*reading file..
while (fscanf(file, "S(%d,%d)", &a, &b) == 2)
{
printf("%d,%d", a, b);
}
fclose(file);
}
}
}
게시 된 코드 (
fscanf()
만
a
을 채우고
1
를 반환으로) 하나의 정수를 읽을 수로
while (2 == fscanf(file, "S(%d,%d)", &a, &b))
{
printf("%d %d", a, b);
}
이 fscanf()
의 반환 값에 대해 2
비교 만에 : 스캔 세트가 필요하지 않습니다
도와 주셔서 감사합니다 ...하지만 여전히 화면에 300,400을 출력하지 않습니다. 아래는 내 전체 코드입니다 : –
괜찮아요. –