fork(1) download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <ctype.h>
  5. #include <errno.h>
  6.  
  7. #define MAXFIELDS 100
  8. #define MAX_LENGTH 245
  9.  
  10. char *dex_data[MAXFIELDS];
  11.  
  12. #define ON 1
  13. #define OFF 0
  14. #define ALL_OK 0
  15. #define NOT_OK 1
  16. #define YES 1
  17. #define NO 0
  18.  
  19. /*********************************************************************/
  20. /* Parse: This function parses each field between the '*'s and */
  21. /* returns the number of fields parsed. */
  22. /*********************************************************************/
  23. int Parse(char *source_strng, char *dex_field[]) {
  24. char *ptr;
  25. short field_count = 0;
  26. short str_ix = 0;
  27. short done_sw = NO;
  28. short new_fld_sw = YES;
  29.  
  30. /* clear out array of dex_field pointers */
  31. field_count = 0;
  32. while ( field_count < MAX_FIELDS ) {
  33. dex_field[field_count] = NULL;
  34. field_count++;
  35. }
  36.  
  37. field_count = 0;
  38. while ( done_sw == NO ) {
  39. /* if we hit a newline, the file contains garbage or only the TRLR record */
  40. if ( source_strng[str_ix] == '\n' ) {
  41. field_count = 0;
  42. done_sw = YES;
  43. }
  44. else {
  45. /* DEX data strings end with Carriage Return and Line Feed characters */
  46. if ( (source_strng[str_ix] == CR) && (source_strng[str_ix+1] == LF) ) {
  47. source_strng[str_ix] = NULL; /* end data field with NULL */
  48. dex_field[field_count] = ptr;
  49. done_sw = YES;
  50. }
  51. else {
  52. if ( source_strng[str_ix] == '*' ) {
  53. source_strng[str_ix] = NULL; /* end data field with NULL */
  54. dex_field[field_count] = ptr;
  55. field_count++;
  56. ptr = NULL;
  57. new_fld_sw = YES;
  58. }
  59. else {
  60. if ( new_fld_sw == YES ) {
  61. ptr = &source_strng[str_ix];
  62. new_fld_sw = NO;
  63. }
  64. }
  65. str_ix++;
  66. }
  67. }
  68. } /* end of while ( done_sw == NO ) */
  69.  
  70. return(field_count);
  71.  
  72. }
  73.  
  74. FILE *Dex_infile;
  75.  
  76. int main(void) {
  77. // your code goes here
  78. short rd_rc;
  79.  
  80. dex_data = malloc(sizeof(char *)*MAXFIELDS);
  81.  
  82. int p;
  83.  
  84. for(p=0; p < MAXFIELDS ; p++)
  85. dex_data[p] = malloc(sizeof(char)*MAX_LENGTH);
  86.  
  87. if( ( Dex_infile = fopen(ws_fullpath_name,"r") ) == NULL ) {
  88. printf("Can Not Open DEX Input File");
  89. exit(1);
  90. }
  91.  
  92. fgets(in_buf,sizeof(in_buf),Dex_infile);
  93.  
  94. if(Parse(in_buf,dex_data) > 0){
  95. rd_rc = 0;
  96. }
  97.  
  98. fclose(Dex_infile);
  99. return 0;
  100. }
  101.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.c: In function ‘Parse’:
prog.c:32:25: error: ‘MAX_FIELDS’ undeclared (first use in this function)
   while ( field_count < MAX_FIELDS ) {
                         ^~~~~~~~~~
prog.c:32:25: note: each undeclared identifier is reported only once for each function it appears in
prog.c:46:38: error: ‘CR’ undeclared (first use in this function)
        if ( (source_strng[str_ix] == CR) && (source_strng[str_ix+1] == LF) ) {
                                      ^~
prog.c:46:72: error: ‘LF’ undeclared (first use in this function)
        if ( (source_strng[str_ix] == CR) && (source_strng[str_ix+1] == LF) ) {
                                                                        ^~
prog.c:47:32: warning: assignment makes integer from pointer without a cast [-Wint-conversion]
           source_strng[str_ix] = NULL;        /* end data field with NULL */
                                ^
prog.c:53:35: warning: assignment makes integer from pointer without a cast [-Wint-conversion]
              source_strng[str_ix] = NULL;     /* end data field with NULL */
                                   ^
prog.c: In function ‘main’:
prog.c:80:12: error: assignment to expression with array type
   dex_data = malloc(sizeof(char *)*MAXFIELDS);
            ^
prog.c:87:29: error: ‘ws_fullpath_name’ undeclared (first use in this function)
    if( ( Dex_infile = fopen(ws_fullpath_name,"r") ) == NULL ) {
                             ^~~~~~~~~~~~~~~~
prog.c:92:8: error: ‘in_buf’ undeclared (first use in this function)
  fgets(in_buf,sizeof(in_buf),Dex_infile);
        ^~~~~~
prog.c:78:8: warning: variable ‘rd_rc’ set but not used [-Wunused-but-set-variable]
  short rd_rc;
        ^~~~~
stdout
Standard output is empty