Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
C++ stdio.h rename function problem
#1
I'm using the header file standard for C++ stdio.h, specifically for the rename function, however one problem to me that I see is that it expects input parameters for const char strings.

The big problem here is the const part that i'm trying to deal with to coincide with what it wants as my inputs. If it wasn't for that everything would be fine...

Here's what i've got so far (Ignore the Usage.h and Usage function, it's not the problem here and that works fine, it's more the loop right around where i'm trying to rename to the new value)

Code:
#include "stdafx.h"
#include "stdio.h"
#include "Usage.h"

#include <string>
#include <iostream>

int main(int argc, char *arg[])
{
    system("color 0F");

    if(argc < 2)
        Usage();
    else
        std::cout << "Beginning Process - Please Wait...\n\n";

    const char* inputf;
    short unsigned int inputl = 0;

    for (__int64 x = 1; x < argc; x++)
    {
        inputf = arg[x];
        inputl = strlen(inputf);
        char Arr[500];

        for (short unsigned int i = 0; i < inputl; i++)
        {
            if (i == 0 || Arr[i-1] == '\\' || Arr[i-1] == ' ') {
                Arr[i] = char(toupper( inputf[i]) );
            } else {
                Arr[i] = char(tolower( inputf[i] ));
            }
        }

        short unsigned int ren_task = 0;
        ren_task = rename(inputf, Arr);

        if ( ren_task == 0 )
            std::cout << "File successfully renamed:\n\t--" << arg[x] << "\n\n";
        else
            std::cout << "Error renaming file: \n\t--" << arg[x] << "\n\n";

    }
    return 0;
    std::cin.get();
}

This line here:
Code:
ren_task = rename(inputf, Arr);

Arr won't convert to a proper "const char *" input, I get a weird value when trying to parse that out. I have tried seeing if I can cast a string from the std namespace over to that specifier, but no avail. It asks for a const value and therefore doesn't want to accept psuedo-const values calculated upon runtime (which is what my loop does), it wants a definite value that it can take in before calculating it to ensure that it stays it's const value and it's a valid value before startup.

Maybe it's just because it's now 3:45AM in Mountain timezone lol... I'll see tomorrow possibly what's going on.
Reply


Messages In This Thread
C++ stdio.h rename function problem - by AceInfinity - 01-14-2012, 03:44 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Visual stdio [c] RANA 0 595 11-28-2010, 09:21 AM
Last Post: RANA
  [C] Factorial function Commodore 1 936 11-28-2010, 07:13 AM
Last Post: RANA
  [C] Prime number function Commodore 2 5,114 10-11-2010, 01:11 PM
Last Post: Commodore
  Problem with a member function of a class charnet3d 2 1,032 10-31-2009, 03:22 AM
Last Post: charnet3d

Forum Jump:


Users browsing this thread: 1 Guest(s)