有一個input.txt
姓名(32)+(1)空格 電話(10)+(1)空格 地址(32)
John Smith 2022233322 300 E.Oak Taipei 10843
Jane Smith 3435245564 200 E.Oak Taipei 10843
John Jorda 3254656555 100 E.Oak Taipei 10843
可是印出來 ---------------->電話數字不對!!!
姓名 電話 地址
John Smith 8189176 300 E.Oak Taipei 10843
Jane Smith 8189176 200 E.Oak Taipei 10843
John Jorda 8189176 100 E.Oak Taipei 10843
可以幫我看看 為何電話數字會跑掉??
謝謝
我的程式如下
#include<stdio.h>
#include<string.h>
int main (void)
{
typedef struct
{
char name[32];
long int telephone;
char address[32];
} RECORD;
RECORD customer;
FILE *fpInput;
FILE *fpt;
fpInput=fopen("input.txt","r");
char buffer[100]={0};
system("clear");
while(fgets(buffer,sizeof(buffer),fpInput)!=NULL)
{
for(i=0;i<32;i++)
customer.name[i]=buffer[i];
customer.name[31]='\0';
sscanf(buffer,"%ld",&customer.telephone);
for(i=0;i<32;i++)
customer.address[i]=buffer[i+44];
customer.address[31]='\0';
printf("%32s %ld %32s\n",customer.name,customer.telephone,customer.address);
}
fclose(fpInput);
}
This entry passed through the Full-Text RSS service — if this is your content and you're reading it on someone else's site, please read the FAQ at fivefilters.org/content-only/faq.php#publishers. Five Filters recommends:
留言列表