char to int, int to char... 
Author Message
 char to int, int to char...

Hi, all. Thanks in advance.

I've reading a couple of nice books and a bunch of tutorials, and finally
decided to write some small program just to satisfy myself.

I have some directory where all the filenames are uppercased. I'm trying
to rename each file to corresponding lowercase letters.
Here's how I approached.

char *filename[MAX];
char fileList[N];
FILE *ifp;

system("ls > tmpfile");
ifp = fopen("tmpfile", "r");

for(int i = 0; fscanf(ifp, "%s", fileList) == 1; ++i) {
        filename[i] = calloc(strlen(fileList) + 1, sizeof(char));
        strcpy(filename[i], fileList);

Quote:
}

Here's the dillema. Now I need to somehow convert this char * to int in
order to use tolower(). Then again I need to convert this int from
tolower() to char *, to later use rename(char *, char *).

How would I do this?
I guess I'm really confused, and am sorry to waste bandwidth with this
newbie question.

Again, thanks in advance.

Dae



Fri, 28 Jul 2000 03:00:00 GMT  
 char to int, int to char...



Quote:
>char *filename[MAX];
>char fileList[N];
>FILE *ifp;

>system("ls > tmpfile");
>ifp = fopen("tmpfile", "r");

>for(int i = 0; fscanf(ifp, "%s", fileList) == 1; ++i) {

     ^^^^^^^^^
This is C++ or C9X (I suspect the former).  Can't do this in C yet.

Quote:
>    filename[i] = calloc(strlen(fileList) + 1, sizeof(char));

sizeof(char)==1, by definition.  No need for calloc() really, as the
strcpy() that follows is going to overwrite all the zeroes calloc()
put into the buffer.  malloc(strlen(fileList)+1) is enough.

Quote:
>    strcpy(filename[i], fileList);
>}

>Here's the dillema. Now I need to somehow convert this char * to int in
>order to use tolower(). Then again I need to convert this int from
>tolower() to char *, to later use rename(char *, char *).

>How would I do this?

The compiler does it for you, if you give tolower() a char at a time:

for(j=0; filename[i][j]!='\0'; j++)
  filename[i][j]=tolower(filename[i][j]);

==
Miguel Carrasquer Vidal                     ~ ~
Amsterdam                   _____________  ~ ~

========================== Ce .sig n'est pas une .cig



Fri, 28 Jul 2000 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. int to char / char to int

2. conversion int to char, char to int ?????

3. char *fnpars(const char *fn, int p, int v)

4. int gethostname(char FAR* name, int len)

5. int main( int argc, char *argv[] )

6. scaning a char and outputing char, int, float??

7. char *strchr(const char *, int) ??!!!

8. int compress(char *buffer, char *output);

9. int func(int) versus int func(int *) efficacy.

10. CMap <char *, char *, int, int> is not working

11. URGENT: int func( int t, int k, char s[t][k] ) right ?

12. int std::system(const char*) function

 

 
Powered by phpBB® Forum Software