Variable Oddities :D

This is a discussion on Variable Oddities :D within the C Programming forums, part of the General Programming Boards category; I have written the following code. It is part of an operating environment for DOS I'm developing, and it's meant ...

  1. #1
    Registered User Unimatrix139's Avatar
    Join Date
    Jun 2002
    Posts
    55

    Exclamation Variable Oddities :D

    I have written the following code. It is part of an operating environment for DOS I'm developing, and it's meant to accertain weather the file in inputstx is described in a data file as restricted to the current user. The function ECIREAD does all the file reading from this file, and it works like this:-

    Code:
    char *eciread(char *locationinfile, char *anotherlocationinfile, int characterstoread, int offsetfromlastlocation, int mode)
    this is it:-

    Code:
    int qfs(char *inputstx) /* Returns 0 for OK, 42 if file is restricted, and 43 if extention is restricted.*/
    {
       char *tmp, tmp3[700], tmp5[700], tmp6[700], *tmp7;
       FILE *tmp4;
       int tmp2;
       tmp2=0;
       tmp7=inputstx;
       do
       {
          tmp3[tmp2]=NULL;
          tmp2=tmp2+1;
       }
       while(tmp2<673);
       tmp2=0;
       strcpy(tmp3, "f=");
       strcat(tmp3, tmp7);
       tmp=eciread("[ACCESS]", tmp3, 700, 0, 1);
       if(tmp!=NULL)
       {
          return(42);
       }
       do
       {
          tmp3[tmp2]=NULL;
          tmp2=tmp2+1;
       }
       while(tmp2<sizeof(tmp3));
       tmp2=0;
       tmp=chkext(tmp7, ".", 0);
       strcpy(tmp3, "x=");
       strcat(tmp3, tmp);
       tmp=eciread("[ACCESS]", tmp3, 700, 0, 1);
       if(tmp!=NULL)
       {
          return(43);
       }
       do
       {
          tmp3[tmp2]=NULL;
          tmp5[tmp2]=NULL;
          tmp6[tmp2]=NULL;
          tmp2=tmp2+1;
       }
       while(tmp2<sizeof(tmp3));   
       tmp2=0;
       system("cd >~qfs.tmo");
       tmp4=fopen("~qfs.tmo", "r");
       do
       {
          tmp=fgets(tmp3, 2, tmp4);
          if(strcmp(tmp, "\n")==0)
          {
             tmp2=32767;
          }
          else
          {
             strcat(tmp6, tmp);
          }
       }
       while(tmp2!=32767);   
       fclose(tmp4);
       tmp2=0;
       do
       {
          tmp3[tmp2]=NULL;
          tmp2=tmp2+1;
       }
       while(tmp2<sizeof(tmp3));   
       strcat(tmp6, "\\");
       strcat(tmp6, tmp7);
       strcpy(tmp3, "f=");
       strcat(tmp3, tmp6);
       strlwr(tmp3);
       tmp=eciread("[ACCESS]", tmp3, 700, 0, 1);
       if(tmp!=NULL)
       {
          return(42);
       }
       return(0);
    }
    When I run it, it changes makes other char * variables previously defiened before main() null values, and I can't tell why. Any ideas?

    ..I just figured out that if I make the first do...while loop go round 672 times instead of 700 it works up til the point of the next loop... And that doesnt help me at all am i missing something blindingly obvious?
    Last edited by Unimatrix139; 07-31-2002 at 07:27 AM.
    Kree'ta Tau'ri! Chaapa'ai!

  2. #2
    Just because ygfperson's Avatar
    Join Date
    Jan 2002
    Posts
    2,493
    just nitpicking here, but
    Code:
    while(tmp2!=32767);
    what use does that have? the best it could do is cause an endless loop, unless you're using multiple threads in which case you wouldn't be using dos anyway.

  3. #3
    Registered User Unimatrix139's Avatar
    Join Date
    Jun 2002
    Posts
    55

    Cool tmp2

    It's meant to trip when the string in 'tmp' becomes '\n' - I'm reading the data from the file but not the \n that's on the end. It's not very good style I know but I'm not a very good programmer! lol

    I hope my 1st post actually meant sense - I read thru it and was confused by my own words
    Kree'ta Tau'ri! Chaapa'ai!

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,484
    1. give all your variables more meaningful names - tmp1 tmp2 etc does not do anything for understanding.

    2. Try splitting the function into a couple of smaller functions which perform something more specific. Long rambling code does not make for good reading, and it's harder to change.

  5. #5
    Registered User Unimatrix139's Avatar
    Join Date
    Jun 2002
    Posts
    55

    Lightbulb ding!

    I've fixed it! I had called ECIREAD in a previous function to obtain the variable that cept becoming corrupt, and found that every time I called ECIREAD from this function is changed what was in the variable that was being corrupted..... I'll avoid that in future! Thanks people!
    Kree'ta Tau'ri! Chaapa'ai!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How accurate is the following...
    By emeyer in forum C Programming
    Replies: 22
    Last Post: 12-07-2005, 11:07 AM
  2. static class variable vs. global variable
    By nadamson6 in forum C++ Programming
    Replies: 18
    Last Post: 09-30-2005, 03:31 PM
  3. Replies: 2
    Last Post: 04-12-2004, 01:37 AM
  4. write Variable and open Variable and get Information
    By cyberbjorn in forum C++ Programming
    Replies: 2
    Last Post: 04-09-2004, 01:30 AM
  5. Variable question I can't find answer to
    By joelmon in forum C++ Programming
    Replies: 3
    Last Post: 02-12-2002, 03:11 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21