close
Blogtrottr
Yahoo!奇摩知識+ - 分類問答 - 電腦網路 - 已解決
Yahoo!奇摩知識+ - 分類問答 - 電腦網路 - 已解決 
Kindle Book Deals

We find the best deals on best-selling Kindle books for you. Just tell us which genres you love and we'll do the rest. The best part? It's completely free!
From our sponsors
c語言 數字跑掉了
Nov 5th 2013, 20:52

有一個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:

You are receiving this email because you subscribed to this feed at blogtrottr.com.

If you no longer wish to receive these emails, you can unsubscribe from this feed, or manage all your subscriptions
arrow
arrow
    全站熱搜
    創作者介紹
    創作者 qfasff 的頭像
    qfasff

    線上遊戲排行榜2013/2014,進擊的巨人線上看,candy crush saga外掛,正妹寫真三圍

    qfasff 發表在 痞客邦 留言(0) 人氣()