943,948 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Marked Solved
  • Views: 2167
  • C RSS
You are currently viewing page 1 of this multi-page discussion thread
Jul 13th, 2009
0

Memory Problem After a certain limit

Expand Post »
Hi All,

My requirement is like this.It a part of a software devlopment team as i am devloping a tool its a part of it.
Its bit long but my explanation is clear to get it.

1)we need to read a data file using a description file.
Usage: programname <description_file> <data_file>
2)Then need to dump the datafile on the screen according to the description file.

Detailed descritpin is given below:

Thanks,
DP

Description file format:
========================

begin
columname datatype("delimeter");
columname datatype("delimeter");
.
.
.
.
end;

EXAMPLE:
--------

begin
name string("|");
age string("|");
sex string("\n");
end;

Datafile Sample:
===============
Deepak|23|M
puja|21|f
|XY|

OUTPUT WILL BE:
================

Record_1:

name:"Deepak"
age:"23"
sex:"M"

Record_2:

name:"puja:
age:"21"
sex:"F"

Record_3:

name:""
age:"XY"
sex:""

I think the picture is clear now what i am doing.

now i am telling about the important functions and structures i am using.

A) The below structure is used to describe the Description file.

typedef struct dml_s
{
char **col_headers;
char **column_delim;
int *col_datatype;
int *col_len;
int col_cnt;
int record_length;
int file_type; //file type can be fixed,delimeted or max len with delimeters
}dml;

concentrate on 3 columns :
===========================

char **col_headers; it will store the column headers from the description file.
char **column_delim; it will store the column delimeters from the description file.
int col_cnt; it will store the column count from the description file.


B) dml* extract_dml_info(char* description_fname,dml *record);

this function will read the description file and store the necessary information in the variables.

C) void read_delimeted(char *data_filename,char **delmimeter,char **header,int col_cnt);

now this fuction will take the data file name along with the data retured by the above function.
and displays data on the screen as per the output format.

++++++++++++++++++++++++++++++++++++++++++++++++
+++++++++++++++++++PROBLEM++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++

1)When we pass hard coded values to the fucntion

void read_delimeted(char *data_filename,char **delmeter,char **header,int col_cnt);

it works fine for any number of columns and any size of data file

e.g
char *delmimeter[]={"name","age","sex");
char *delimeter[]={"|","|","\n"};

2)When we pass values returned from extract_dml_info(char* description_fname,dml *record);

to the fucntion read_delimeted(char *data_filename,char **delmeter,char **header,int col_cnt);

it works upto 10 columns.

when the column name exceeds 10

it shows "segmentation fault"

ANALYSIS:
==========
A)
if error in

read_delimeted(char *data_filename,char **delmeter,char **header,int col_cnt);

then it should not have worked for hard coded values.

B)if error in extract_dml_info(char* description_fname,dml *record);

then it should not print datas extrated beyond 10 columns but it prints data for any number of
columns.

but as a whole

program fails if the column number from descrition file exceeds 10 columns.
Similar Threads
Reputation Points: 22
Solved Threads: 12
Junior Poster
Dream2code is offline Offline
144 posts
since Jun 2009
Jul 13th, 2009
0

Re: Memory Problem After a certaion limit

Stand alone code is pasted below:
i have compiled it on gcc compiler on 64bit mode.

e.g gcc -o output prog.c -m64

code below
===========
  1. #include<stdio.h>
  2. #include<math.h>
  3. #include<stdlib.h>
  4.  
  5. #define FIXED 1
  6. #define DELIMETED 2
  7. #define MIXED 3
  8.  
  9. int errno;
  10.  
  11. typedef struct dml_s
  12. {
  13. char **col_headers;
  14. char **column_delim;
  15. int *col_datatype;
  16. int *col_len;
  17. int col_cnt;
  18. int record_length;
  19. int file_type; //file type can be fixed,delimeted or max len with delimeters
  20. }dml;
  21.  
  22.  
  23. void display_intro();
  24. dml* extract_dml_info(char*,dml*);
  25. int str_wc(char *);
  26. int str_semicl(char *);
  27. int pow_user(int,int);
  28. void display_dml_info(struct dml_s *record);
  29. void read_fixed(char *filename,int *size,char **header,int col_cnt,int record_len);
  30. void read_delimeted(char *filename,char **delmimeter,char **header,int col_cnt);
  31. char * ustrtok(char *base_string,char *next_str,char *delim);
  32.  
  33. int main(int argc,char *argv[])
  34. {
  35.  
  36. if(argc!=3)
  37. {
  38. display_intro();
  39. return;
  40. }
  41.  
  42.  
  43. dml *record;
  44. record=(dml*)malloc(sizeof(dml));
  45. record=extract_dml_info(argv[1],record);
  46. if(record==NULL) exit(1);
  47.  
  48. display_dml_info(record);
  49.  
  50.  
  51. if(record->file_type==DELIMETED)
  52. {
  53.  
  54. read_delimeted(argv[2],record->column_delim,record->col_headers,record->col_cnt);
  55. }
  56.  
  57.  
  58. /*
  59. else if(record->file_type=FIXED)
  60. {
  61. read_fixed(argv[2],record->col_len,record->col_headers,record->col_cnt,record->record_length);
  62. }
  63.  
  64. else if(record->file_type=MIXED)
  65. {
  66. printf("\n\nCONSTRUCTION ON PROGRESS FOR DELIMTED FILE WITH LENGTH\n");
  67. return;
  68. }
  69. */
  70.  
  71. return 0;
  72. }
  73.  
  74.  
  75.  
  76.  
  77.  
  78. /********************THIS FUNCTION EXTRACTS INFORMATION FROM THE
  79. *********************DML FILE AND RETURNS A STRUCTRUE***********/
  80.  
  81. dml* extract_dml_info(char *dmlfile,dml *record)
  82. {
  83. char buffer[100]; //IT BUFFERS ONE LINE AT A TIME FORM THE FILE
  84. char **line; //ALL THE LINES FROM THE FILE STORED IN LINE ARRAY
  85. char **col_desc; //STORES THE COLUMN DESCRIPTIONS
  86. char *temp,*token;
  87. FILE *fp;
  88. int i,j;
  89.  
  90. fp=fopen(dmlfile,"r");
  91. if(fp==NULL)
  92. {
  93. printf("Can't read from file: \"%s\"\n",dmlfile);
  94. perror("Error");
  95. exit(1);
  96. }
  97.  
  98. record=(dml*)malloc(20*sizeof(dml));
  99. record->col_headers=(char**)malloc(200*sizeof(char*));
  100. record->column_delim=(char**)malloc(200*sizeof(char*));
  101. col_desc=(char**)malloc(200*sizeof(char*));
  102. line=(char**)malloc(200*sizeof(char*));
  103.  
  104. fgets(buffer,100,fp);
  105. i=0;
  106. while(!feof(fp))
  107. {
  108. if(buffer[strlen(buffer)-1]=='\n')
  109. buffer[strlen(buffer)-1]='\0';
  110. line[i]=(char*)malloc(strlen(buffer)+1);
  111. strcpy(line[i],buffer);
  112. i++;
  113. fgets(buffer,100,fp);
  114. }
  115.  
  116. record->col_cnt=i-2; //Getting the column count from the dml file
  117.  
  118.  
  119.  
  120. /****************DML VALIDATION***************************************
  121. The following validation taken place
  122. 1)DML starts with a 'begin' flag and end with 'end;'
  123. 2)Every statement ends with a semicolon except the begin
  124. 3)no semicolon should encounter inside
  125. 4)each line should consist of 2 words (a)column name (b)column desc
  126. *********************************************************************/
  127.  
  128. if(strcmp(line[0],"begin")!=0)
  129. {
  130. printf("Dml Error: at line 1\n");
  131. }
  132.  
  133. int k=0;
  134. int w_count,semicl_flag;
  135. for(j=1;j<i;j++)
  136. {
  137. k=strlen(line[j]);
  138.  
  139.  
  140. if(line[j][k-1]!=';')
  141. {
  142. printf("Dml error: Missing ; at line %d\n",j+1);
  143. return NULL;
  144. }
  145. if((strchr(line[j],';'))!=NULL && line[j][k-1]!=';' )
  146. {
  147. printf("Dml error: at line %d\n",j+1);
  148. return NULL;
  149. }
  150.  
  151.  
  152. w_count=str_wc(line[j]);
  153. if( w_count != 2 && w_count != 3 && j!=i-1 )
  154. {
  155. printf("Dml Error xxx at line %d\n",j);
  156. return NULL;
  157. }
  158.  
  159. semicl_flag=str_semicl(line[j]);
  160. if(semicl_flag==-1)
  161. {
  162. printf("Dml Error yyy at line %d\n",j);
  163. return NULL;
  164. }
  165. else if(semicl_flag==-2)
  166. {
  167. printf("Dml Error zzz at line %d\n",j);
  168. return NULL;
  169. }
  170. }
  171.  
  172. if(strcmp(line[i-1],"end;")!=0)
  173. {
  174. printf("Dml Error: at line %d\n",i);
  175. return NULL;
  176. }
  177.  
  178. /****************END DML VALIDATION***********************/
  179.  
  180.  
  181. for(j=0;j<record->col_cnt;j++)
  182. {
  183. token=(char*)malloc(strlen(line[j])+1);
  184. token=strtok(line[j+1]," ");
  185. if(token==NULL)
  186. {
  187. token="\0";
  188. return NULL;
  189. }
  190. record->col_headers[j]=(char*)malloc(strlen(token)+1);
  191. strcpy(record->col_headers[j],token);
  192. token=strtok(NULL,"\n");
  193. col_desc[j]=(char*)malloc(strlen(token)+1);
  194. if(token!=NULL)
  195. strcpy(col_desc[j],token);
  196. else
  197. {
  198. printf("Incorrect DML at line %d for %s\n",j+1,record->col_headers[j]);
  199. return NULL;
  200. }
  201.  
  202. }
  203.  
  204.  
  205.  
  206. /****************DETERMINE THE DATATYPE OF THE COLUMNS*********/
  207. char *del;
  208. record->col_datatype=(int*)malloc(2*i*sizeof(int));
  209. int flag;
  210. for(j=0;j<record->col_cnt;j++)
  211. {
  212. del=strstr(col_desc[j],"string");
  213. if(del==NULL)
  214. {
  215. record->col_datatype[j]=1;
  216. del='\0';
  217. }
  218. else
  219. record->col_datatype[j]=0;
  220. }
  221. /*****************************************************************/
  222.  
  223.  
  224. int count_fixed=0;
  225. int count_del=0;
  226. char *temp_del_fst;
  227. char *temp_del_lst;
  228. int tempv;
  229. record->column_delim=(char**)malloc(10*sizeof(char*));
  230. for(j=0;j<record->col_cnt;j++)
  231. {
  232. temp_del_fst=strchr(col_desc[j],'"');
  233. temp_del_lst=strrchr(col_desc[j],'"');
  234. if(temp_del_fst==NULL && temp_del_lst==NULL)
  235. {
  236. count_fixed++;
  237. record->column_delim[j]=(char*)malloc(2);
  238. record->column_delim[j]="\0";
  239. }
  240. else if(temp_del_fst!=NULL && temp_del_lst!=NULL && temp_del_lst!=temp_del_fst)
  241. {
  242. count_del++;
  243. tempv=temp_del_lst-temp_del_fst;
  244. record->column_delim[j]=(char*)malloc(temp_del_lst-temp_del_fst);
  245. strncpy(record->column_delim[j],temp_del_fst+1,temp_del_lst-temp_del_fst-1);
  246. }
  247. else if(temp_del_fst!=NULL && temp_del_lst!=NULL && temp_del_lst==temp_del_fst)
  248. {
  249. printf("DML Error :at line %d ,inproper description\n",j+1);
  250. record->column_delim[j]="\0";
  251. return NULL;
  252. }
  253. }
  254.  
  255.  
  256.  
  257. //printf("count fixed:%d and count del :%d \n",count_fixed,count_del);
  258. /***********/
  259.  
  260. record->record_length=0;
  261. char *c_len;
  262. if(count_fixed==record->col_cnt && count_del==0)
  263. {
  264. record->file_type=FIXED;
  265. record->col_len=(int *)malloc(record->col_cnt*sizeof(int));
  266. for(j=0;j<record->col_cnt;j++)
  267. {
  268. temp_del_fst=strchr(col_desc[j],'(');
  269. temp_del_lst=strrchr(col_desc[j],')');
  270. if(temp_del_fst==NULL && temp_del_lst==NULL)
  271. {
  272. printf("Dml Error..( ) missing in column description\n");
  273. }
  274. tempv=temp_del_lst-temp_del_fst;
  275.  
  276. c_len=(char*)malloc(10*sizeof(char));
  277. strncpy(c_len,temp_del_fst+1,temp_del_lst-temp_del_fst-1);
  278.  
  279. int len=strlen(c_len);
  280.  
  281. record->col_len[j]=atoi(c_len);
  282. record->record_length=record->record_length+record->col_len[j];
  283. // printf("length:%d\tclen:%s\tlen:%d\t j=%d\n",record->col_len[j],c_len,tempv,j);
  284.  
  285. }
  286.  
  287. //printf("record length is :%d\n",record->record_length);
  288.  
  289. }
  290.  
  291.  
  292. /**********/
  293. else if(count_fixed==0 && count_del==record->col_cnt)
  294. {
  295. record->file_type=DELIMETED;
  296.  
  297. if(strcmp(record->column_delim[record->col_cnt-1],"\\n")!=0)
  298. {
  299. printf("DML error,in the last field '\\n' missing\n");
  300. return NULL;
  301. }
  302. }
  303. else
  304. {
  305. record->file_type=-1;
  306. printf("DML error,Unable to determine the file type\n");
  307. return NULL;
  308. }
  309.  
  310. return record;
  311. }
  312.  
  313.  
  314. /******A function to get the word count of a string*******/
  315.  
  316. int str_wc(char *str)
  317. {
  318. int limit = strlen(str);
  319. int i, change = 1, words = 0;
  320. for(i = 0; i < limit; ++i)
  321. {
  322. if(!isspace(str[i]))
  323. {
  324. if(change)
  325. {
  326. ++words;
  327. change = 0;
  328. }
  329. }
  330. else
  331. {
  332. change = 1;
  333. }
  334. }
  335.  
  336. return words;
  337. }
  338.  
  339. /*************************************************************/
  340.  
  341. /*********A fucntion to check semicolon occurs in between the line***/
  342.  
  343. int str_semicl(char *str)
  344. {
  345. int limit = strlen(str);
  346. int i,flag=0;
  347.  
  348. for(i = 0; i < limit; ++i)
  349. {
  350. if(i < limit-1 && str[i]==';' )
  351. {
  352. flag=-1;
  353. }
  354.  
  355. else if( str[limit-1]==';' && isspace(str[limit-2]) )
  356. {
  357. flag=-2;
  358. }
  359. else if( str[limit-1]==';' && !(isspace(str[limit-2])))
  360. {
  361. flag=0;
  362. }
  363.  
  364. else
  365. flag=0;
  366.  
  367. }
  368.  
  369. return flag;
  370. }
  371.  
  372. /************************************************************/
  373.  
  374. /******CALCULATION POWER****************/
  375. int pow_user(base,exp)
  376. {
  377. int i;
  378. int pow=1;
  379. for(i=0;i<exp;i++)
  380. {
  381. pow=pow*base;
  382. }
  383. return pow;
  384. }
  385. /****************************************/
  386.  
  387.  
  388. /******IT'S A FUNCTION SIMILAR TO STRTOK BUT CAN HANDLE NULL VALUES******/
  389. /******THIS FUNCTION SPILTS A STRING INTO TWO STRINGS W.R.T A TOKEN******/
  390.  
  391. char * ustrtok(char *base_string,char *next_str,char *delim)
  392. {
  393. char *str2;
  394. str2=(char*)malloc(100);
  395. if(base_string==NULL && strlen(base_string)<1)
  396. {
  397. next_str=NULL;
  398. return NULL;
  399. }
  400. int len=strlen(base_string);
  401. char *temp;
  402. temp=(char*)malloc(100);
  403.  
  404. temp=strstr(base_string,delim);
  405. if(temp==NULL)
  406. {
  407. strcpy(next_str,base_string);
  408. next_str[strlen(next_str)]='\0';
  409. return NULL;
  410. }
  411. else
  412. {
  413. int sub_len=temp-base_string;
  414. str2=(char*)malloc(100);
  415. strncpy(str2,base_string,sub_len);
  416. str2[strlen(str2)]='\0';
  417. strcpy(next_str,str2);
  418. return (temp+strlen(delim));
  419. }
  420. }
  421.  
  422.  
  423.  
  424. /******************THIS FUNCTION DISPLAYS THE DML DESCRIPTION****************/
  425.  
  426.  
  427. void display_dml_info(dml *record)
  428. {
  429.  
  430. int i,j;
  431. if(record==NULL)return;
  432. printf("=========================\n");
  433. printf("NO OF COLUMNS:%d\n",record->col_cnt);
  434. printf("RECORD LENGTH:%d\n",record->record_length);
  435. printf("FILE TYPE :\"%d\"\n",record->file_type);
  436. printf("=========================\n");
  437.  
  438. for(j=0;j<record->col_cnt;j++)
  439. {
  440. printf("===COLUMN %d===\n\n",j+1);
  441. printf("HEADER:\"%s\"\n",record->col_headers[j]);
  442. printf("DATATYPE:\"%d\"\n",record->col_datatype[j] );
  443. if(record->file_type==DELIMETED)printf("DELIMETER:\"%s\"\n",record->column_delim[j]);
  444. if(record->file_type==FIXED )printf("LENGTH:%d\n",record->col_len[j]);
  445. }
  446. printf("=========================\n\n");
  447. }
  448.  
  449. /***************************************************************************************/
  450.  
  451.  
  452.  
  453. /*****************************Begin read_fixed**************************************
  454.  
  455. THIS FUNCTION READS A FIXED LENGTH FILE AS PER THE SPECIFED DML STEPS ARE AS FOLLOWS:
  456.  
  457. INPUT PARAMETER:
  458. A) File Name
  459. B) Column Headers
  460. C) Length of all the Columns
  461. D) No Of columns
  462. E) Lenggh of Each Record
  463.  
  464. OUTPUT:
  465.  
  466. Reads the file as per the input parametes and Display it on the Screen
  467.  
  468. *********************************************************************************/
  469.  
  470.  
  471. void read_fixed(char *filename,int *size,char **header,int col_cnt,int record_len)
  472. {
  473. FILE *file_read;
  474. long lSize;
  475. char * buffer;
  476. size_t result;
  477. fpos_t position;
  478.  
  479.  
  480. file_read=fopen(filename,"rb");
  481. if(file_read==NULL)
  482. {
  483. printf("Can't read from file \"%s\"\n",filename);
  484. perror("Error");
  485. exit(1);
  486. }
  487.  
  488.  
  489. fseek(file_read,0,SEEK_END);
  490. lSize=ftell(file_read);
  491. rewind(file_read);
  492.  
  493. int j=0;
  494. int i=0;
  495. float record_count=lSize/record_len;
  496. int multiply=record_count*record_len;
  497.  
  498. buffer=(char*)malloc(4);
  499. result=fread(buffer,1,size[0],file_read);
  500. buffer[size[0]]='\0';
  501. rewind(file_read);
  502. while(!feof(file_read) || buffer==NULL )
  503. {
  504. if(j>=col_cnt)j=0;
  505. if(j==0 && i<=record_count)
  506. {
  507. i++;
  508. }
  509. if(j==0 && i<=record_count)
  510. {
  511. printf("Record %d\n",i);
  512. printf("=============\n");
  513. }
  514.  
  515. buffer=(char*)malloc(10);
  516. result=fread(buffer,1,size[j],file_read);
  517. buffer[size[j]]='\0';
  518. if(i<=record_count)
  519. printf("%s:\"%s\"\n",header[j],buffer);
  520. free(buffer);
  521. j++;
  522. }
  523.  
  524. /*setting up the file pointer to get the leftover bytes*/
  525. fgetpos (file_read, &position);
  526. position=(fpos_t)multiply;
  527. fsetpos (file_read, &position);
  528. /******************************************************/
  529. if(lSize!=multiply)
  530. {
  531.  
  532. char *left_over;
  533. left_over=(char*)malloc(record_len+1);
  534. result=fread(left_over,1,record_len,file_read);
  535. left_over[record_len]='\0';
  536. printf("\n\n\nLeft Over Bytes:\"%s\"\n",left_over);
  537. free(left_over);
  538.  
  539. printf("\nError:Incomplete record at end of file.\n");
  540. printf("Either (1) The metadata does not accurately describe the data,\n");
  541. printf(" or (2) The data has somehow been corrupted.\n");
  542. }
  543. }
  544.  
  545. /*********************************END read_fixed ****************************/
  546.  
  547.  
  548.  
  549. void read_delimeted(char *filename,char **column_delim,char **col_headers,int col_cnt)
  550. {
  551. FILE *data_file;
  552. char buffer[20000];
  553. char *ext_line=NULL;
  554. char *temp=NULL;
  555. char **fields=NULL;
  556. int i,j;
  557.  
  558. printf("filename:%s\n",filename);
  559. printf("columncount:%d\n",col_cnt);
  560. for(i=0;i<col_cnt;i++)
  561. {
  562. printf("del:%s\n",column_delim[i]);
  563. printf("header:%s\n",col_headers[i]);
  564. }
  565.  
  566.  
  567.  
  568.  
  569.  
  570.  
  571. data_file=fopen(filename,"r");
  572. if(data_file==NULL)
  573. {
  574. printf("can't open file\n");
  575. return;
  576. }
  577.  
  578. printf("TESTING BREAK1\n");
  579.  
  580. j=1;
  581. fgets(buffer,2000,data_file);
  582. while(!feof(data_file))
  583. {
  584. i=0;
  585.  
  586. if(buffer[strlen(buffer)-1]=='\n')
  587. buffer[strlen(buffer)-1]='\0';
  588. if(strlen(buffer)==0)
  589. goto nextline;
  590. ext_line=(char*)malloc(strlen(buffer)+1);
  591. if(ext_line==NULL)
  592. {
  593. printf("NUll Record Found\n");
  594. }
  595. strcpy(ext_line,buffer);
  596. printf("\nRecord %d:\n",j);
  597. printf("=========\n");
  598.  
  599. fields=(char**)malloc(col_cnt*sizeof(char*));
  600. char *next_str;
  601. temp=(char*)malloc(strlen(buffer)+1);
  602. next_str=(char*)malloc(strlen(buffer)+1);
  603. next_str=ustrtok(ext_line,temp,column_delim[0]);
  604. while(i<col_cnt)
  605. {
  606. if(next_str==NULL)
  607. next_str="\0";
  608. if(ext_line==NULL)
  609. ext_line="\0";
  610. if(temp==NULL)
  611. temp="\0";
  612.  
  613.  
  614. fields[i]=(char*)malloc(strlen(temp));
  615. strcpy(fields[i],temp);
  616.  
  617. fprintf(stdout,"%s:\"%s\"\n",col_headers[i],fields[i]);
  618. ext_line=next_str;
  619. free(temp);
  620. temp=(char*)malloc(100*sizeof(char));
  621. if(i==col_cnt-1)
  622. {
  623. column_delim[i+1]=column_delim[i];
  624. }
  625. next_str=ustrtok(ext_line,temp,column_delim[i+1]);
  626.  
  627.  
  628. if(i==col_cnt-2)
  629. {
  630. if(ext_line==NULL)
  631. ext_line="\0";
  632. strcpy(temp,ext_line);
  633. }
  634.  
  635. if(i==col_cnt-1 && strlen(ext_line)>0)
  636. {
  637. printf("\n\nError:Incomplete field at end of record.\n");
  638. printf("Leftover bytes :\"%s\"\n",ext_line);
  639. printf("Either (1) The metadata does not accurately describe the data,\n");
  640. printf(" or (2) The data has somehow been corrupted.\n");
  641. }
  642. i++;
  643. }
  644. j++;
  645. nextline:
  646. fgets(buffer,2000,data_file);
  647. free(fields);
  648. }
  649. fclose(data_file);
  650. }
  651.  
  652.  
  653.  
  654. void display_intro()
  655. {
  656. printf("\n mdump: Version 1.0\n\n");
  657. printf(" Copyright (c) 2009, Deepak Panigrahy. All rights reserved.\n\n");
  658. printf(" Purpose: This program is a simple utility that display\n");
  659. printf(" the source file as per the Record format.\n\n");
  660.  
  661. printf(" Usage: mdump <Dml FileName> <Data FileName>\n\n");
  662.  
  663. printf(" Use -h option for additional help.\n");
  664. }
Last edited by Ancient Dragon; Jul 13th, 2009 at 9:52 pm. Reason: add code tags
Reputation Points: 22
Solved Threads: 12
Junior Poster
Dream2code is offline Offline
144 posts
since Jun 2009
Jul 13th, 2009
0

Re: Memory Problem After a certaion limit

http://www.daniweb.com/forums/announcement118-3.html
http://www.daniweb.com/forums/announcement118-3.html
http://www.daniweb.com/forums/announcement118-3.html
http://www.daniweb.com/forums/announcement118-3.html
http://www.daniweb.com/forums/announcement118-3.html
You already missed at least FIVE places where the board asks (nay, implores) you to use code tags, but you missed them all.

Try editing your posts again, and this time see if you can make them more readable.
Check out some other posts on the forum for readability, and make sure yours is just as good.
Team Colleague
Reputation Points: 5862
Solved Threads: 950
Posting Sage
Salem is offline Offline
7,164 posts
since Dec 2005
Jul 13th, 2009
0

Re: Memory Problem After a certaion limit

for more detail:
================

instread of strtok i have used my own advanced function ustrtok.

it works like this
==================

char * ustrtok(char *base_string,char *next_str,char *delim);

return=ustrtok(char *base_string,char *next_str,char *delim);

basesting= a|b|c|d
next_str=NULL
delim=|

after one call
===============
next_str=a
return=b|c|d

then we need to assing

base_string=return for further calls.

note:
1)No issue due to this function its only a help to understand the code.
2)i have tried my besr from my side.please look into this.
3)i have provided the sample data u can run the code very easily to see the output.
4)i suggest run the code with different type of descrition files and data files
change the columns numbers and all then u will observe the failure or else it works fine.
Reputation Points: 22
Solved Threads: 12
Junior Poster
Dream2code is offline Offline
144 posts
since Jun 2009
Jul 13th, 2009
0

Re: Memory Problem After a certaion limit

sory friend i appolize for this.okie i am posting my code again.


  1.  
  2. #include<stdio.h>
  3. #include<math.h>
  4. #include<stdlib.h>
  5.  
  6. #define FIXED 1
  7. #define DELIMETED 2
  8. #define MIXED 3
  9.  
  10. int errno;
  11.  
  12. typedef struct dml_s
  13. {
  14. char **col_headers;
  15. char **column_delim;
  16. int *col_datatype;
  17. int *col_len;
  18. int col_cnt;
  19. int record_length;
  20. int file_type; //file type can be fixed,delimeted or max len with delimeters
  21. }dml;
  22.  
  23.  
  24. void display_intro();
  25. dml* extract_dml_info(char*,dml*);
  26. int str_wc(char *);
  27. int str_semicl(char *);
  28. int pow_user(int,int);
  29. void display_dml_info(struct dml_s *record);
  30. void read_fixed(char *filename,int *size,char **header,int col_cnt,int record_len);
  31. void read_delimeted(char *filename,char **delmimeter,char **header,int col_cnt);
  32. char * ustrtok(char *base_string,char *next_str,char *delim);
  33.  
  34. int main(int argc,char *argv[])
  35. {
  36.  
  37. if(argc!=3)
  38. {
  39. display_intro();
  40. return;
  41. }
  42.  
  43.  
  44. dml *record;
  45. record=(dml*)malloc(sizeof(dml));
  46. record=extract_dml_info(argv[1],record);
  47. if(record==NULL) exit(1);
  48.  
  49. display_dml_info(record);
  50.  
  51.  
  52. if(record->file_type==DELIMETED)
  53. {
  54.  
  55. read_delimeted(argv[2],record->column_delim,record->col_headers,record->col_cnt);
  56. }
  57.  
  58.  
  59. /*
  60. else if(record->file_type=FIXED)
  61. {
  62. read_fixed(argv[2],record->col_len,record->col_headers,record->col_cnt,record->record_length);
  63. }
  64.  
  65. else if(record->file_type=MIXED)
  66. {
  67. printf("\n\nCONSTRUCTION ON PROGRESS FOR DELIMTED FILE WITH LENGTH\n");
  68. return;
  69. }
  70. */
  71.  
  72. return 0;
  73. }
  74.  
  75.  
  76.  
  77.  
  78.  
  79. /********************THIS FUNCTION EXTRACTS INFORMATION FROM THE
  80. *********************DML FILE AND RETURNS A STRUCTRUE***********/
  81.  
  82. dml* extract_dml_info(char *dmlfile,dml *record)
  83. {
  84. char buffer[100]; //IT BUFFERS ONE LINE AT A TIME FORM THE FILE
  85. char **line; //ALL THE LINES FROM THE FILE STORED IN LINE ARRAY
  86. char **col_desc; //STORES THE COLUMN DESCRIPTIONS
  87. char *temp,*token;
  88. FILE *fp;
  89. int i,j;
  90.  
  91. fp=fopen(dmlfile,"r");
  92. if(fp==NULL)
  93. {
  94. printf("Can't read from file: \"%s\"\n",dmlfile);
  95. perror("Error");
  96. exit(1);
  97. }
  98.  
  99. record=(dml*)malloc(20*sizeof(dml));
  100. record->col_headers=(char**)malloc(200*sizeof(char*));
  101. record->column_delim=(char**)malloc(200*sizeof(char*));
  102. col_desc=(char**)malloc(200*sizeof(char*));
  103. line=(char**)malloc(200*sizeof(char*));
  104.  
  105. fgets(buffer,100,fp);
  106. i=0;
  107. while(!feof(fp))
  108. {
  109. if(buffer[strlen(buffer)-1]=='\n')
  110. buffer[strlen(buffer)-1]='\0';
  111. line[i]=(char*)malloc(strlen(buffer)+1);
  112. strcpy(line[i],buffer);
  113. i++;
  114. fgets(buffer,100,fp);
  115. }
  116.  
  117. record->col_cnt=i-2; //Getting the column count from the dml file
  118.  
  119.  
  120.  
  121. /****************DML VALIDATION***************************************
  122. The following validation taken place
  123. 1)DML starts with a 'begin' flag and end with 'end;'
  124. 2)Every statement ends with a semicolon except the begin
  125. 3)no semicolon should encounter inside
  126. 4)each line should consist of 2 words (a)column name (b)column desc
  127. *********************************************************************/
  128.  
  129. if(strcmp(line[0],"begin")!=0)
  130. {
  131. printf("Dml Error: at line 1\n");
  132. }
  133.  
  134. int k=0;
  135. int w_count,semicl_flag;
  136. for(j=1;j<i;j++)
  137. {
  138. k=strlen(line[j]);
  139.  
  140.  
  141. if(line[j][k-1]!=';')
  142. {
  143. printf("Dml error: Missing ; at line %d\n",j+1);
  144. return NULL;
  145. }
  146. if((strchr(line[j],';'))!=NULL && line[j][k-1]!=';' )
  147. {
  148. printf("Dml error: at line %d\n",j+1);
  149. return NULL;
  150. }
  151.  
  152.  
  153. w_count=str_wc(line[j]);
  154. if( w_count != 2 && w_count != 3 && j!=i-1 )
  155. {
  156. printf("Dml Error xxx at line %d\n",j);
  157. return NULL;
  158. }
  159.  
  160. semicl_flag=str_semicl(line[j]);
  161. if(semicl_flag==-1)
  162. {
  163. printf("Dml Error yyy at line %d\n",j);
  164. return NULL;
  165. }
  166. else if(semicl_flag==-2)
  167. {
  168. printf("Dml Error zzz at line %d\n",j);
  169. return NULL;
  170. }
  171. }
  172.  
  173. if(strcmp(line[i-1],"end;")!=0)
  174. {
  175. printf("Dml Error: at line %d\n",i);
  176. return NULL;
  177. }
  178.  
  179. /****************END DML VALIDATION***********************/
  180.  
  181.  
  182. for(j=0;j<record->col_cnt;j++)
  183. {
  184. token=(char*)malloc(strlen(line[j])+1);
  185. token=strtok(line[j+1]," ");
  186. if(token==NULL)
  187. {
  188. token="\0";
  189. return NULL;
  190. }
  191. record->col_headers[j]=(char*)malloc(strlen(token)+1);
  192. strcpy(record->col_headers[j],token);
  193. token=strtok(NULL,"\n");
  194. col_desc[j]=(char*)malloc(strlen(token)+1);
  195. if(token!=NULL)
  196. strcpy(col_desc[j],token);
  197. else
  198. {
  199. printf("Incorrect DML at line %d for %s\n",j+1,record->col_headers[j]);
  200. return NULL;
  201. }
  202.  
  203. }
  204.  
  205.  
  206.  
  207. /****************DETERMINE THE DATATYPE OF THE COLUMNS*********/
  208. char *del;
  209. record->col_datatype=(int*)malloc(2*i*sizeof(int));
  210. int flag;
  211. for(j=0;j<record->col_cnt;j++)
  212. {
  213. del=strstr(col_desc[j],"string");
  214. if(del==NULL)
  215. {
  216. record->col_datatype[j]=1;
  217. del='\0';
  218. }
  219. else
  220. record->col_datatype[j]=0;
  221. }
  222. /*****************************************************************/
  223.  
  224.  
  225. int count_fixed=0;
  226. int count_del=0;
  227. char *temp_del_fst;
  228. char *temp_del_lst;
  229. int tempv;
  230. record->column_delim=(char**)malloc(10*sizeof(char*));
  231. for(j=0;j<record->col_cnt;j++)
  232. {
  233. temp_del_fst=strchr(col_desc[j],'"');
  234. temp_del_lst=strrchr(col_desc[j],'"');
  235. if(temp_del_fst==NULL && temp_del_lst==NULL)
  236. {
  237. count_fixed++;
  238. record->column_delim[j]=(char*)malloc(2);
  239. record->column_delim[j]="\0";
  240. }
  241. else if(temp_del_fst!=NULL && temp_del_lst!=NULL && temp_del_lst!=temp_del_fst)
  242. {
  243. count_del++;
  244. tempv=temp_del_lst-temp_del_fst;
  245. record->column_delim[j]=(char*)malloc(temp_del_lst-temp_del_fst);
  246. strncpy(record->column_delim[j],temp_del_fst+1,temp_del_lst-temp_del_fst-1);
  247. }
  248. else if(temp_del_fst!=NULL && temp_del_lst!=NULL && temp_del_lst==temp_del_fst)
  249. {
  250. printf("DML Error :at line %d ,inproper description\n",j+1);
  251. record->column_delim[j]="\0";
  252. return NULL;
  253. }
  254. }
  255.  
  256.  
  257.  
  258. //printf("count fixed:%d and count del :%d \n",count_fixed,count_del);
  259. /***********/
  260.  
  261. record->record_length=0;
  262. char *c_len;
  263. if(count_fixed==record->col_cnt && count_del==0)
  264. {
  265. record->file_type=FIXED;
  266. record->col_len=(int *)malloc(record->col_cnt*sizeof(int));
  267. for(j=0;j<record->col_cnt;j++)
  268. {
  269. temp_del_fst=strchr(col_desc[j],'(');
  270. temp_del_lst=strrchr(col_desc[j],')');
  271. if(temp_del_fst==NULL && temp_del_lst==NULL)
  272. {
  273. printf("Dml Error..( ) missing in column description\n");
  274. }
  275. tempv=temp_del_lst-temp_del_fst;
  276.  
  277. c_len=(char*)malloc(10*sizeof(char));
  278. strncpy(c_len,temp_del_fst+1,temp_del_lst-temp_del_fst-1);
  279.  
  280. int len=strlen(c_len);
  281.  
  282. record->col_len[j]=atoi(c_len);
  283. record->record_length=record->record_length+record->col_len[j];
  284. // printf("length:%d\tclen:%s\tlen:%d\t j=%d\n",record->col_len[j],c_len,tempv,j);
  285.  
  286. }
  287.  
  288. //printf("record length is :%d\n",record->record_length);
  289.  
  290. }
  291.  
  292.  
  293. /**********/
  294. else if(count_fixed==0 && count_del==record->col_cnt)
  295. {
  296. record->file_type=DELIMETED;
  297.  
  298. if(strcmp(record->column_delim[record->col_cnt-1],"\\n")!=0)
  299. {
  300. printf("DML error,in the last field '\\n' missing\n");
  301. return NULL;
  302. }
  303. }
  304. else
  305. {
  306. record->file_type=-1;
  307. printf("DML error,Unable to determine the file type\n");
  308. return NULL;
  309. }
  310.  
  311. return record;
  312. }
  313.  
  314.  
  315. /******A function to get the word count of a string*******/
  316.  
  317. int str_wc(char *str)
  318. {
  319. int limit = strlen(str);
  320. int i, change = 1, words = 0;
  321. for(i = 0; i < limit; ++i)
  322. {
  323. if(!isspace(str[i]))
  324. {
  325. if(change)
  326. {
  327. ++words;
  328. change = 0;
  329. }
  330. }
  331. else
  332. {
  333. change = 1;
  334. }
  335. }
  336.  
  337. return words;
  338. }
  339.  
  340. /*************************************************************/
  341.  
  342. /*********A fucntion to check semicolon occurs in between the line***/
  343.  
  344. int str_semicl(char *str)
  345. {
  346. int limit = strlen(str);
  347. int i,flag=0;
  348.  
  349. for(i = 0; i < limit; ++i)
  350. {
  351. if(i < limit-1 && str[i]==';' )
  352. {
  353. flag=-1;
  354. }
  355.  
  356. else if( str[limit-1]==';' && isspace(str[limit-2]) )
  357. {
  358. flag=-2;
  359. }
  360. else if( str[limit-1]==';' && !(isspace(str[limit-2])))
  361. {
  362. flag=0;
  363. }
  364.  
  365. else
  366. flag=0;
  367.  
  368. }
  369.  
  370. return flag;
  371. }
  372.  
  373. /************************************************************/
  374.  
  375. /******CALCULATION POWER****************/
  376. int pow_user(base,exp)
  377. {
  378. int i;
  379. int pow=1;
  380. for(i=0;i<exp;i++)
  381. {
  382. pow=pow*base;
  383. }
  384. return pow;
  385. }
  386. /****************************************/
  387.  
  388.  
  389. /******IT'S A FUNCTION SIMILAR TO STRTOK BUT CAN HANDLE NULL VALUES******/
  390. /******THIS FUNCTION SPILTS A STRING INTO TWO STRINGS W.R.T A TOKEN******/
  391.  
  392. char * ustrtok(char *base_string,char *next_str,char *delim)
  393. {
  394. char *str2;
  395. str2=(char*)malloc(100);
  396. if(base_string==NULL && strlen(base_string)<1)
  397. {
  398. next_str=NULL;
  399. return NULL;
  400. }
  401. int len=strlen(base_string);
  402. char *temp;
  403. temp=(char*)malloc(100);
  404.  
  405. temp=strstr(base_string,delim);
  406. if(temp==NULL)
  407. {
  408. strcpy(next_str,base_string);
  409. next_str[strlen(next_str)]='\0';
  410. return NULL;
  411. }
  412. else
  413. {
  414. int sub_len=temp-base_string;
  415. str2=(char*)malloc(100);
  416. strncpy(str2,base_string,sub_len);
  417. str2[strlen(str2)]='\0';
  418. strcpy(next_str,str2);
  419. return (temp+strlen(delim));
  420. }
  421. }
  422.  
  423.  
  424.  
  425. /******************THIS FUNCTION DISPLAYS THE DML DESCRIPTION****************/
  426.  
  427.  
  428. void display_dml_info(dml *record)
  429. {
  430.  
  431. int i,j;
  432. if(record==NULL)return;
  433. printf("=========================\n");
  434. printf("NO OF COLUMNS:%d\n",record->col_cnt);
  435. printf("RECORD LENGTH:%d\n",record->record_length);
  436. printf("FILE TYPE :\"%d\"\n",record->file_type);
  437. printf("=========================\n");
  438.  
  439. for(j=0;j<record->col_cnt;j++)
  440. {
  441. printf("===COLUMN %d===\n\n",j+1);
  442. printf("HEADER:\"%s\"\n",record->col_headers[j]);
  443. printf("DATATYPE:\"%d\"\n",record->col_datatype[j] );
  444. if(record->file_type==DELIMETED)printf("DELIMETER:\"%s\"\n",record->column_delim[j]);
  445. if(record->file_type==FIXED )printf("LENGTH:%d\n",record->col_len[j]);
  446. }
  447. printf("=========================\n\n");
  448. }
  449.  
  450. /***************************************************************************************/
  451.  
  452.  
  453.  
  454. /*****************************Begin read_fixed**************************************
  455.  
  456. THIS FUNCTION READS A FIXED LENGTH FILE AS PER THE SPECIFED DML STEPS ARE AS FOLLOWS:
  457.  
  458. INPUT PARAMETER:
  459. A) File Name
  460. B) Column Headers
  461. C) Length of all the Columns
  462. D) No Of columns
  463. E) Lenggh of Each Record
  464.  
  465. OUTPUT:
  466.  
  467. Reads the file as per the input parametes and Display it on the Screen
  468.  
  469. *********************************************************************************/
  470.  
  471.  
  472. void read_fixed(char *filename,int *size,char **header,int col_cnt,int record_len)
  473. {
  474. FILE *file_read;
  475. long lSize;
  476. char * buffer;
  477. size_t result;
  478. fpos_t position;
  479.  
  480.  
  481. file_read=fopen(filename,"rb");
  482. if(file_read==NULL)
  483. {
  484. printf("Can't read from file \"%s\"\n",filename);
  485. perror("Error");
  486. exit(1);
  487. }
  488.  
  489.  
  490. fseek(file_read,0,SEEK_END);
  491. lSize=ftell(file_read);
  492. rewind(file_read);
  493.  
  494. int j=0;
  495. int i=0;
  496. float record_count=lSize/record_len;
  497. int multiply=record_count*record_len;
  498.  
  499. buffer=(char*)malloc(4);
  500. result=fread(buffer,1,size[0],file_read);
  501. buffer[size[0]]='\0';
  502. rewind(file_read);
  503. while(!feof(file_read) || buffer==NULL )
  504. {
  505. if(j>=col_cnt)j=0;
  506. if(j==0 && i<=record_count)
  507. {
  508. i++;
  509. }
  510. if(j==0 && i<=record_count)
  511. {
  512. printf("Record %d\n",i);
  513. printf("=============\n");
  514. }
  515.  
  516. buffer=(char*)malloc(10);
  517. result=fread(buffer,1,size[j],file_read);
  518. buffer[size[j]]='\0';
  519. if(i<=record_count)
  520. printf("%s:\"%s\"\n",header[j],buffer);
  521. free(buffer);
  522. j++;
  523. }
  524.  
  525. /*setting up the file pointer to get the leftover bytes*/
  526. fgetpos (file_read, &position);
  527. position=(fpos_t)multiply;
  528. fsetpos (file_read, &position);
  529. /******************************************************/
  530. if(lSize!=multiply)
  531. {
  532.  
  533. char *left_over;
  534. left_over=(char*)malloc(record_len+1);
  535. result=fread(left_over,1,record_len,file_read);
  536. left_over[record_len]='\0';
  537. printf("\n\n\nLeft Over Bytes:\"%s\"\n",left_over);
  538. free(left_over);
  539.  
  540. printf("\nError:Incomplete record at end of file.\n");
  541. printf("Either (1) The metadata does not accurately describe the data,\n");
  542. printf(" or (2) The data has somehow been corrupted.\n");
  543. }
  544. }
  545.  
  546. /*********************************END read_fixed ****************************/
  547.  
  548.  
  549.  
  550. void read_delimeted(char *filename,char **column_delim,char **col_headers,int col_cnt)
  551. {
  552. FILE *data_file;
  553. char buffer[20000];
  554. char *ext_line=NULL;
  555. char *temp=NULL;
  556. char **fields=NULL;
  557. int i,j;
  558.  
  559. printf("filename:%s\n",filename);
  560. printf("columncount:%d\n",col_cnt);
  561. for(i=0;i<col_cnt;i++)
  562. {
  563. printf("del:%s\n",column_delim[i]);
  564. printf("header:%s\n",col_headers[i]);
  565. }
  566.  
  567.  
  568.  
  569.  
  570.  
  571.  
  572. data_file=fopen(filename,"r");
  573. if(data_file==NULL)
  574. {
  575. printf("can't open file\n");
  576. return;
  577. }
  578.  
  579. printf("TESTING BREAK1\n");
  580.  
  581. j=1;
  582. fgets(buffer,2000,data_file);
  583. while(!feof(data_file))
  584. {
  585. i=0;
  586.  
  587. if(buffer[strlen(buffer)-1]=='\n')
  588. buffer[strlen(buffer)-1]='\0';
  589. if(strlen(buffer)==0)
  590. goto nextline;
  591. ext_line=(char*)malloc(strlen(buffer)+1);
  592. if(ext_line==NULL)
  593. {
  594. printf("NUll Record Found\n");
  595. }
  596. strcpy(ext_line,buffer);
  597. printf("\nRecord %d:\n",j);
  598. printf("=========\n");
  599.  
  600. fields=(char**)malloc(col_cnt*sizeof(char*));
  601. char *next_str;
  602. temp=(char*)malloc(strlen(buffer)+1);
  603. next_str=(char*)malloc(strlen(buffer)+1);
  604. next_str=ustrtok(ext_line,temp,column_delim[0]);
  605. while(i<col_cnt)
  606. {
  607. if(next_str==NULL)
  608. next_str="\0";
  609. if(ext_line==NULL)
  610. ext_line="\0";
  611. if(temp==NULL)
  612. temp="\0";
  613.  
  614.  
  615. fields[i]=(char*)malloc(strlen(temp));
  616. strcpy(fields[i],temp);
  617.  
  618. fprintf(stdout,"%s:\"%s\"\n",col_headers[i],fields[i]);
  619. ext_line=next_str;
  620. free(temp);
  621. temp=(char*)malloc(100*sizeof(char));
  622. if(i==col_cnt-1)
  623. {
  624. column_delim[i+1]=column_delim[i];
  625. }
  626. next_str=ustrtok(ext_line,temp,column_delim[i+1]);
  627.  
  628.  
  629. if(i==col_cnt-2)
  630. {
  631. if(ext_line==NULL)
  632. ext_line="\0";
  633. strcpy(temp,ext_line);
  634. }
  635.  
  636. if(i==col_cnt-1 && strlen(ext_line)>0)
  637. {
  638. printf("\n\nError:Incomplete field at end of record.\n");
  639. printf("Leftover bytes :\"%s\"\n",ext_line);
  640. printf("Either (1) The metadata does not accurately describe the data,\n");
  641. printf(" or (2) The data has somehow been corrupted.\n");
  642. }
  643. i++;
  644. }
  645. j++;
  646. nextline:
  647. fgets(buffer,2000,data_file);
  648. free(fields);
  649. }
  650. fclose(data_file);
  651. }
  652.  
  653.  
  654.  
  655. void display_intro()
  656. {
  657. printf("\n mdump: Version 1.0\n\n");
  658. printf(" Copyright (c) 2009, Deepak Panigrahy. All rights reserved.\n\n");
  659. printf(" Purpose: This program is a simple utility that display\n");
  660. printf(" the source file as per the Record format.\n\n");
  661.  
  662. printf(" Usage: mdump <Dml FileName> <Data FileName>\n\n");
  663.  
  664. printf(" Use -h option for additional help.\n");
  665. }
Reputation Points: 22
Solved Threads: 12
Junior Poster
Dream2code is offline Offline
144 posts
since Jun 2009
Jul 13th, 2009
0

Re: Memory Problem After a certaion limit

Shame about the indentation - good luck.
Team Colleague
Reputation Points: 5862
Solved Threads: 950
Posting Sage
Salem is offline Offline
7,164 posts
since Dec 2005
Jul 13th, 2009
0

Re: Memory Problem After a certaion limit

i have written the code in notepad and compiled in UNIX environment with gcc compiler so couldn't emphasized on the indentation.

sorry again salem.

i am eagerly waiting for a solution.

salem, it will be appreciable if u go to the code.
Last edited by Dream2code; Jul 13th, 2009 at 2:47 pm.
Reputation Points: 22
Solved Threads: 12
Junior Poster
Dream2code is offline Offline
144 posts
since Jun 2009
Jul 13th, 2009
1

Re: Memory Problem After a certaion limit

use code tags correctly. and make sure your code is indented. otherwise, it's a ridiculous mess, and no one will want to look at it.

[code=c]
  1. int main(void)
  2. {
  3. // hello, i am properly formatted C code.
  4. // aren't i nice?
  5.  
  6. if (your_code == properly_formatted)
  7. {
  8. youWillGetResponse = TRUE;
  9. }
  10. else
  11. {
  12. youWillGetResponse = NULL;
  13. }
  14.  
  15. return toBeginning(andTryAgain);
  16. }
[/code]
Last edited by jephthah; Jul 13th, 2009 at 6:10 pm.
Reputation Points: 2143
Solved Threads: 178
Posting Maven
jephthah is offline Offline
2,567 posts
since Feb 2008
Jul 13th, 2009
0

Re: Memory Problem After a certaion limit

Try making a smaller example of the problems... that program looks a over complicated. If what you have work's, exept for a few errors, don't worry about changing it. Here's how I would go around doing it:
First read the description file to make a sscanf string, and make two arrays, one to hold the names of the variables, and another to hold the variables. Since the datatype can vary, maybe make the second array an array of pointers.
Next read the data file, record by record and as you index along print out the variables with there names.
Good luck.
Last edited by Hiroshe; Jul 13th, 2009 at 6:56 pm.
Reputation Points: 431
Solved Threads: 17
Posting Whiz in Training
Hiroshe is offline Offline
255 posts
since Jun 2008
Jul 13th, 2009
0

Re: Memory Problem After a certaion limit

Click to Expand / Collapse  Quote originally posted by Dream2code ...
i have written the code in notepad and compiled in UNIX environment with gcc compiler .
The most horrible programming environment ever. Why code it on Windows and compile it on *nix? You have a perfectly good IDE on *nix called vi, and I know for a fact there are even better ones. On Windows you have several free IDEs that will do auto-intent -- VC++ 2008 Express and Code::Bocks are just two of them. Learn to use IDEs because they will make your life a lot simpler so that you can become a more efficient coder.

And if you still insist on using Notepad, I know it has a tab key -- learn to use it.
Last edited by Ancient Dragon; Jul 13th, 2009 at 9:59 pm.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,953 posts
since Aug 2005

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: Finding the number of variables equal to a certain value
Next Thread in C Forum Timeline: falling letters





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC