What seems to be the problem here!!

This is a discussion on What seems to be the problem here!! within the C Programming forums, part of the General Programming Boards category; Code: #include <stdio.h> #include <windows.h> // ***************************************************************** // This portion checks to see if you are in the right directory ...

  1. #1
    Registered User
    Join Date
    Jun 2005
    Posts
    108

    What seems to be the problem here!!

    Code:
    #include <stdio.h>
    #include <windows.h>
    
    // *****************************************************************
    // This portion checks to see if you are in the right directory
    // If Year is non-existant then new Year folder is created
    // If Day is non-existant then new Day is created within year
    // Dates are taken from GPS Conversion portion
    // *****************************************************************
    
    void main()
    
    {
    
    int year, day, hour, PRN, prev_year, prev_hour;
    
    year = 2100;		////////////////////////////////////////////////////////////////////////////////
    day = 100;			////////////////////////////////////////////////////////////////////////////////
    hour = 20;			//////////////////////JUST FOR TESTING PURPOSES/////////////////////////////////
    PRN = 122;			////////////////////////////////////////////////////////////////////////////////
    prev_year = 1999;   ////////////////////////////////////////////////////////////////////////////////
    prev_hour = 19;		////////////////////////////////////////////////////////////////////////////////
    
    char string_variable [200];
    
    (prev_year = year - 1);
    (prev_hour = hour - 1);
    
    	if (year == prev_year + 1)
    
    {		sprintf(string_variable, "c:\\temp\\PRN%3d\\Y%4d\\d%3d\\h%2d.ems", PRN, year, day, hour);
    	}
    	else (sprintf(string_variable, "c:\\temp\\PRN%3d\\Y%4d\\d%3d\\h%2d.ems", PRN, year, day, hour) == NULL);
    
    
    if (hour == prev_hour + 1)
    
    {		sprintf(string_variable, "c:\\temp\\PRN%3d\\Y%4d\\d%3d\\h%2d.ems", PRN, year, day, hour);
    	}
    else (sprintf(string_variable, "c:\\temp\\PRN%3d\\Y%4d\\d%3d\\h%2d.ems", PRN, year, day, hour) == NULL);
    
    }
    
    //***********************************
    //End of Folder checking section
    //***********************************
    the code executes but no files or folders are produced :-(

  2. #2
    Registered User mitakeet's Avatar
    Join Date
    Jun 2005
    Location
    Maryland, USA
    Posts
    212
    Why would it? I don't see any place where it would, all I see is a bunch of sprintf's

    Free code: http://sol-biotech.com/code/.

    It is not that old programmers are any smarter or code better, it is just that they have made the same stupid mistake so many times that it is second nature to fix it.
    --Me, I just made it up

    The reasonable man adapts himself to the world; the unreasonable one persists in trying to adapt the world to himself. Therefore, all progress depends on the unreasonable man.
    --George Bernard Shaw

  3. #3
    Registered User
    Join Date
    Jun 2005
    Posts
    108
    oops!!

    ill be right back!!

  4. #4
    Registered User
    Join Date
    Jun 2005
    Posts
    108
    Code:
    #include <stdio.h>
    #include <windows.h>
    #include <stdio.h>
    #include <iostream>
    #include <stdlib.h>
    #include <time.h>
    // *****************************************************************
    // This portion checks to see if you are in the right directory
    // If Year is non-existant then new Year folder is created
    // If Day is non-existant then new Day is created within year
    // Dates are taken from GPS Conversion portion
    // *****************************************************************
    
    void main()
    
    {
    
    int year, hour, day, PRN, prev_year, prev_hour;
    
    {
    
    year = 2100;		////////////////////////////////////////////////////////////////////////////////
    day = 100;			////////////////////////////////////////////////////////////////////////////////
    PRN = 122;			//////////////////////JUST FOR TESTING PURPOSES/////////////////////////////////
    hour = 20;					////////////////////////////////////////////////////////////////////////////////
    prev_year = 1999;   ////////////////////////////////////////////////////////////////////////////////
    prev_hour = 19;		////////////////////////////////////////////////////////////////////////////////
    
    char string_variable [200];
    
    (prev_year = year - 1);
    (prev_hour = hour - 1);
    
    	if (year == prev_year + 1)
    
    {		sprintf(string_variable, "c:\\temp\\PRN%3d\\Y%4d\\d%3d\\h%2d.ems", PRN, year, day, hour);
    		CreateDirectory("c:\\temp\\PRN%3d\\Y%4d\\d%3d", NULL);
    	}
    	else (sprintf(string_variable, "c:\\temp\\PRN%3d\\Y%4d\\d%3d\\h%2d.ems", PRN, year, day, hour) == NULL);
    
    
    if (hour == prev_hour + 1)
    
    {		sprintf(string_variable, "c:\\temp\\PRN%3d\\Y%4d\\d%3d\\h%2d.ems", PRN, year, day, hour);
    		CreateDirectory("c:\\temp\\PRN%3d\\Y%4d\\d%3d", NULL);
    	}
    else (sprintf(string_variable, "c:\\temp\\PRN%3d\\Y%4d\\d%3d\\h%2d.ems", PRN, year, day, hour) == NULL);
    
    }
    
    }
    but this should work, right?

  5. #5
    Registered User mitakeet's Avatar
    Join Date
    Jun 2005
    Location
    Maryland, USA
    Posts
    212
    I ran a C beautifier on your code and put in a couple of braces to show you exactly how the code is executing. Take a close look and see if this is really what you want.

    Code:
    #include <stdio.h>
    #include <windows.h>
    #include <stdio.h>
    #include <iostream>
    #include <stdlib.h>
    #include <time.h>
    
    void main() {
        int year, hour, day, PRN, prev_year, prev_hour;
        {
            year = 2100;
            day = 100;
            PRN = 122;
            hour = 20;
            prev_year = 1999;
            prev_hour = 19;
            char string_variable [200];
    
            (prev_year = year - 1);
            (prev_hour = hour - 1);
    
            if (year == prev_year + 1) {
                sprintf(string_variable, "c:\\temp\\PRN%3d\\Y%4d\\d%3d\\h%2d.ems", PRN, year, day, hour);
                CreateDirectory("c:\\temp\\PRN%3d\\Y%4d\\d%3d", NULL);
            }else{
                (sprintf(string_variable, "c:\\temp\\PRN%3d\\Y%4d\\d%3d\\h%2d.ems", PRN, year, day, hour) == NULL);
            }
    
            if (hour == prev_hour + 1) {
                sprintf(string_variable, "c:\\temp\\PRN%3d\\Y%4d\\d%3d\\h%2d.ems", PRN, year, day, hour);
                CreateDirectory("c:\\temp\\PRN%3d\\Y%4d\\d%3d", NULL);
            }else{
                (sprintf(string_variable, "c:\\temp\\PRN%3d\\Y%4d\\d%3d\\h%2d.ems", PRN, year, day, hour) == NULL);
            }
    
        }
    
    }

    Free code: http://sol-biotech.com/code/.

    It is not that old programmers are any smarter or code better, it is just that they have made the same stupid mistake so many times that it is second nature to fix it.
    --Me, I just made it up

    The reasonable man adapts himself to the world; the unreasonable one persists in trying to adapt the world to himself. Therefore, all progress depends on the unreasonable man.
    --George Bernard Shaw

  6. #6
    Registered User
    Join Date
    Jun 2005
    Posts
    108
    I changed it to this so the folders are created correctly but it still doesnt work!

    almost about to cry now!!

    thanks for your help so far!

    Code:
    #include <stdio.h>
    #include <windows.h>
    #include <iostream>
    #include <stdlib.h>
    #include <time.h>
    // *****************************************************************
    // This portion checks to see if you are in the right directory
    // If Year is non-existant then new Year folder is created
    // If Day is non-existant then new Day is created within year
    // Dates are taken from GPS Conversion portion
    // *****************************************************************
    
    void main() {
        int year, hour, day, PRN, prev_year, prev_hour, prev_day;
        {
            year = 2100;
            day = 100;
            PRN = 122;
            hour = 20;
            prev_year = 1999;
            prev_hour = 19;
    		prev_day = 99;
            char string_variable [200];
    
            (prev_year = year - 1);
            (prev_hour = hour - 1);
    		(prev_day = day - 1);
    
            if (year == prev_year + 1) {
                sprintf(string_variable, "c:\\temp\\PRN%3d\\Y%4d", PRN, year, day, hour);
                CreateDirectory("c:\\temp\\PRN%3d\\Y%4d", NULL);
    			printf("new year created\n");
            }else{
                (sprintf(string_variable, "c:\\temp\\PRN%3d\\Y%4d\\d%3d\\h%2d.ems", PRN, year, day, hour) == NULL);
            }
    
            if (day == prev_day + 1) {
                sprintf(string_variable, "c:\\temp\\PRN%3d\\Y%4d\\d%3d", PRN, year, day, hour);
                CreateDirectory("c:\\temp\\PRN%3d\\Y%4d\\d%3d", NULL);
    			printf("new day created\n");
            }else{
                (sprintf(string_variable, "c:\\temp\\PRN%3d\\Y%4d\\d%3d\\h%2d.ems", PRN, year, day, hour) == NULL);
    			
           if (hour == prev_hour + 1) {
                sprintf(string_variable, "c:\\temp\\PRN%3d\\Y%4d\\d%3d\\h%2d.ems", PRN, year, day, hour);
                CreateDirectory("c:\\temp\\PRN%3d\\Y%4d\\d%3d\\h%2d.ems", NULL);
    			printf("new hour created\n");
           }else{
                (sprintf(string_variable, "c:\\temp\\PRN%3d\\Y%4d\\d%3d\\h%2d.ems", PRN, year, day, hour) == NULL);
           }
    
        }
    
    }
    }

  7. #7
    Registered User
    Join Date
    Jun 2005
    Posts
    108
    tried a few other methods and would like the answer to the riddle!!


  8. #8
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Can you be more explicit? What doesn't work exactly? What are you expecting from your program? Is this the directory name you want created:

    "c:\temp\PRN%3d\Y%4d\d%3d"

    or do you want it to be more like

    "c:\temp\PRN122\Y2100\d100"
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  9. #9
    Registered User
    Join Date
    Jun 2005
    Posts
    108
    i would like the second version.

    thats it!!

  10. #10
    Registered User
    Join Date
    Jun 2005
    Posts
    108
    i got it.

    thanks for everyones help anyway

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help understanding a problem
    By dnguyen1022 in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2009, 04:21 PM
  2. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 10:22 AM
  3. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 08:38 AM
  4. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  5. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM

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