Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

cÎļþ²Ù×÷

#include <stdio.h>
#include <stdlib.h> //use malloc, free
#include <string.h> //use memset
#include <ctype.h> //use isdigit
#define ERROR_ILLEGAL_CHAR 1 //define error illegal character as 1
#define ERROR_NUMBERS_DIF 2 //define error numbers is not the same in different line as 2
#define ERROR_FILE_ERROR 3 //define error file error as 3
typedef struct _node{
int num;
struct _node *next;
}node;
node *head = NULL;
void insert(int num)
{
if (NULL == head)
{
head = (node*)malloc(sizeof(node));
(*head).num = num;
(*head).next = NULL;
}
else
{
node* p = head;
while (NULL != p->next) //move to end
{
p = p->next;
}
p->next = (node*)malloc(sizeof(node));
p = p->next;
(*p).num = num;
(*p).next = NULL;
}
}
void output(int rows, int cols)
{
node *p = head;
if (NULL == p)
return;
for (int i=0; i<rows; i++)
{
for (int j=0; j<cols; j++)
{
printf("%-4d", p->num);
p = p->next;
}
printf("\n");
}
}
int getData(int *row, int *col)
{
FILE *f;
char ch = 0;
char t[100];
int index = 0;
int countline = 0;
int totalline = 0;
/*ÈôÎļþÄÚÈÝÊÇÔÚ³ÌÐòÖÐÒÔ¶þ½øÖÆ·½Ê½´ò¿ªÐ´ÈëµÄÊý¾ÝÔò½«´ò¿ª·½Ê½¸ÄΪ"rb"*/
if ((f=fopen("D:\\source\\read.dat", "r")) == NULL)
{
return ERROR_FILE_ERROR;
}
memset(t, -1, 100);
do
{
ch = fgetc(f);
if (isdigit(ch))
{
t[index++] = ch;
continue;
}
else
{
switch (ch)
{
case ',':
case '.':
case ' ':
if ((-1 != t[0]))
{
insert(atoi(t));
memset(t, -1, 100);
index = 0;
countline++;
}
break;
case EOF:
case '\n':
if ((-1 == t[0]) && (0 == countline))//null line
{
break;
}
else
{
if (-1 != t[0])
{
insert(atoi(t));
memset(t, -1, 100);
index = 0;
countline++;
}
}
if (0 != countline)
{
if (0 == totalline)
{
totalline = countline;
*col = totalline;
}
else
{
if (countline != totalline)
{
return ERROR_NUMBERS_DIF;
}


Ïà¹ØÎĵµ£º

CÓëC++µÄÇø±ð

1. C++ËäÈ»Ö÷ÒªÊÇÒÔCµÄ»ù´¡·¢Õ¹ÆðÀ´µÄÒ»ÃÅÐÂÓïÑÔ£¬µ«Ëý²»ÊÇCµÄÌæ´úÆ·£¬²»ÊÇCµÄÉý¼¶£¬C++ºÍCÊÇÐֵܹØϵ¡£Ã»ÓÐË­±ÈË­ÏȽøµÄ˵·¨£¬¸üÖØÒªµÄÒ»µãÊÇCºÍC++¸÷×Եıê׼ίԱ»áÊǶÀÁ¢µÄ£¬×îеÄC++±ê×¼ÊÇC++98£¬×îеÄC±ê×¼ÊÇC99¡£Òò´ËҲûÓÐÏÈѧCÔÙ˵C++µÄ˵·¨£¬Ò²²»ÔÙ£¨×¢ÒâÕâ¸ö"²»ÔÙ"£©ÓÐC++Óï·¨ÊÇCÓï·¨µÄ³¬¼¯µÄ˵·¨¡£
2. C++/CL ......

cµ÷ÓÃapi´ò¿ªÎļþ¶Ô»°¿ò

#include <windows.h>
int WINAPI WinMain( HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nShowCmd )
{
OPENFILENAME ofn;
//ÔÚÄÚ´æÖпª±ÙÒ»¿é¿Õ¼ä£¬´æ·ÅÓû§Ñ¡È¡µÄÎļþÃû
char szFile[MAX_PATH];//MAX_PATH ......

C/C++ÖÐnearºÍfarµÄÇø±ð

C/C++ÖÐnearºÍfarµÄÇø±ð
      ¹Ø¼ü×ÖnearºÍfarÊÜÄ¿±ê¼ÆËã»úÌåϵ½á¹¹µÄÓ°Ï졣Ŀǰ±à³ÌÖÐʹÓò»¶à¡£
      near¹Ø¼ü×Ö´´½¨Ò»¸öÖ¸Ïò¿ÉÑ°Ö·ÄÚ´æµÍ¶Ë²¿·ÖµÄÄ¿±êÖ¸Õë¡£ÕâЩָÕëÕ¼ÓÃÄÚ´æµÄµ¥Ò»×Ö½Ú£¬²¢ÇÒËûÃÇÄܹ»Ö¸ÏòµÄÄÚ´æµ¥Ôª±»ÏÞÖƵ½256¸öλÖã¬Í¨³£ÊÇÔÚ0x0000~0x00ff·¶Î ......

CÖ¸Õë

 
Ö¸ÕëÊÇcºÍc++ÖеÄÄѵãºÍÖص㡣ÎÒÖ»¾«Í¨dosϵÄbasic¡£cÓïÑÔµÄÆäËü¸÷ÖÖÌØÐÔ£¬ÔÚbasicÖж¼ÓÐÀàËƵĶ«Î÷¡£Ö»ÓÐÖ¸Õ룬ÊÇbaiscËù²»¾ß±¸µÄ¡£Ö¸ÕëÊÇcµÄÁé»ê¡£
ÎÒ²»ÏëÖظ´´ó¶àÊýÊéÉÏ˵µÃºÜÇå³þµÄ¶«Î÷£¬ÎÒÖ»ÊÇ°ÑÎÒ¿´¹ýµÄÊéÖÐ˵µÃ²»Çå³þ»òûÓÐ˵£¬¶øÎÒÓÖ¾õµÃÎÒÀí½âµÃÓеãµÀÀíµÄ¶«Î÷д³öÀ´¡£ÎÒµÄÄ¿µÄÊÇ£º
1¡£Í¨¹ýдÕâЩ¶«Î ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ