?? tools.h
字號:
#ifndef TOOLS1
#define TOOLS1
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define TRUE 1
#define FALSE 0
#define columnInconsistant -4
#define numberFormError -3
#define strError -2
#define openFileError -1
#define correctAction 0
#define extraSpace 3
/* ------------------- Define of Global Variables ------------------ */
char seps[] = " ,:;\t\r\n";
/* ------------------- Define of Macros ------------------ */
#define SUCCESS(a) if(a == NULL) { printf("\nUnsuccessful Allocation"); exit(1);}
/* ------------------- Define of Functions ------------------ */
int cal_lines(char *inFile);
int getLengthOfLongestLine(char *inFile);
int AllocateDataSpace(double ***pData, int row, int col);
/* ------------------- Implementation of Functions ------------------ */
/* count lines in the input file, according to the number of new line characters in the file */
int cal_lines(char * inFile) {
FILE *in_fp;
int lines, ch=-10000;
if( (in_fp = fopen( inFile, "r" )) == NULL ) {
printf( "The file '%s' was not opened\n", inFile );
exit(1);
}
lines = 0;
while( feof( in_fp ) == 0) {
while(ch != 10 && feof( in_fp ) == 0)
ch = fgetc( in_fp );
lines++;
if(ch==10)
ch = fgetc( in_fp );
}
fclose(in_fp);
return lines;
}
/* go through the file, to find the length of the longest line in the file */
int getLengthOfLongestLine(char *inFile) {
FILE *in_fp;
int longestLength, length, ch;
if( (in_fp = fopen( inFile, "r" )) == NULL ) {
printf( "The file '%s' was not opened\n", inFile );
exit(1);
}
longestLength = 0;
while( feof( in_fp ) == 0) {
/* get the length of the current line */
length = 0;
ch = fgetc( in_fp );
while(ch != 10 && feof( in_fp ) == 0) {
length++;
ch = fgetc( in_fp );
}
if(longestLength < length) {
longestLength = length;
}
}
fclose(in_fp);
return longestLength;
}
/*---------------------------------------------------------------------------*/
int AllocateDataSpace(double ***pData, int row, int col) {
int i;
double** Data;
Data = (double**)malloc(sizeof(double*) * row);
SUCCESS( Data );
for(i=0; i < row; i++) {
Data[ i ] = (double *)malloc(sizeof(double) * col);
SUCCESS( Data[ i ] );
}
(*pData) = Data;
return correctAction;
}
#endif
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -