易截截图软件、单文件、免安装、纯绿色、仅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写的3D迷宫

          Boss说,要看OpenGL,看了快一个月,总算出了个像样的东西,用C写了个3D迷宫,
虽然只有350行
       代码,不过边学边写,足足写了一周时间,还是小有成就感的,活活活!
         &n ......

在屏幕上画图的C#实现代码


DllImport所在的名字空间 using System.Runtime.InteropServices;
[DllImport("User32.dll")]
        public extern static System.IntPtr GetDC(System.IntPtr hWnd);   
        private void button19_Click(obj ......

常用C头文件及其在标准C++中的保留

头文件的作用
早期的编程语言如Basic、Fortran 没有头文件的概念,C++/C 语言的初学者虽然会用使用头文件,但常常不明其理。这里对头文件的作用略作解释:
(1)通过头文件来调用库功能。在很多场合,源代码不便(或不准)向用户公布,只要向用户提供头文件和二进制的库即可。用户只需要按照头文件中的接口声明来调用库功 ......

C 和 C++ 字符串字面量

C 和 C++ 字符串字面量(String Literal)既有相同之处,又有一些区别。了解这些内容对于加深字符串字面量以及相关一些概念的理解、澄清一些常见的概念误区不无助益。本文以普通字符串字面量 "hello" 为例总结说明如下。
相同点:
字符串字面量是对象
C/C++ 中的对象(Object)指的是一块存储区。字符串字面量是不需要创 ......

c判断汉字

#include <windows.h>
int IsGB(PTSTR pText);
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
     PSTR szCmdLine, int iCmdShow)
{
 static TCHAR szText[] = {TEXT ("i服,了。uy")} ;
 PTSTR pText;
 int i;
 unsigned char ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号