C语言读取串口

http://blog.csdn.net/codexy/article/details/5390550

 

直接上代码:

#include <stdio.h>
#include <windows.h>

int main(void)
{
    FILE *fp;
    char temp;
    char buf[100];
    if((fp=fopen("com5","r"))==NULL) puts("Can't open com3 /n");
    while(1)
    {
        temp=0;
        fscanf(fp,"%c",&temp);
        if(temp!=0)
            putchar(temp);
        else
            Sleep(100);
    }
    fclose(fp);
    return 0;
}

 

posted @ 2016-05-30 10:19  Merlin-magic  阅读(2235)  评论(0编辑  收藏  举报