當前位置:編程學習大全網 - 源碼下載 - 急求源碼。用c語言模擬實現壹個短息的收發。可以簡單壹點發送就是存儲起來,可以實現查看等功能。

急求源碼。用c語言模擬實現壹個短息的收發。可以簡單壹點發送就是存儲起來,可以實現查看等功能。

#include <stdio.h>

#include <string.h>

#include <stdlib.h>

#include <time.h>

void main(void)

{

FILE *fp;

char txt[500];

int cmd;

int i;

time_t rawtime;

struct tm * timeinfo;

fp = fopen("msg.txt", "a+");

if (NULL==fp)

{

printf("open file error!\n");

return;

}

while (1)

{

printf("輸入命令(1:收短信,2:發短信, 0:退出):");

scanf("%d",&cmd);

switch(cmd) {

case 1:

i = 0;

fseek(fp, 0, SEEK_SET); //跳到文件開頭

while(NULL !=fgets(txt, 500, fp))

{

i++;

printf("msg[%d]: %s", i, txt);

}

break;

case 2:

fseek(fp, 0, SEEK_END); //從文件結尾開始寫入

time ( &rawtime );

timeinfo = localtime ( &rawtime );

asctime (timeinfo);

fprintf (fp, "[%4d-%02d-%02d %02d:%02d:%02d] ",1900+timeinfo->tm_year, 1+timeinfo->tm_mon, \

timeinfo->tm_mday,timeinfo->tm_hour,timeinfo->tm_min,timeinfo->tm_sec);

printf("\n輸入命令短信內容(不超過500個字符):");

scanf("%s", txt);

fprintf(fp, "%s\n", txt);

break;

case 0:

fclose(fp);

return; //退出

default:

printf("未定義命令!\n");

break;

}

}

}

  • 上一篇:想學python從哪裏入手
  • 下一篇:鋯石內核源代碼
  • copyright 2024編程學習大全網