-3

I have a some problems writing a code in which I want to modify a file extension stored in a string.For example string bla/bla/file.icc i want to be changed to bla/bla/file.cmr. This string makes part from a structure. I have 2 issues. One is that strcpy gives this message "expected expression before td_ActDOR and second one is in for and give's this message subscribed value is neither array nor pointer.

Here is my code:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef struct s_ActDOR
{
    char pDOR_file[86];
}td_ActDOR;


int main(void)
{
    char path[80]="blabla/blabla/aici.icc";
    td_ActDOR *Obiect;
    Obiect = (td_ActDOR *)malloc(sizeof (td_ActDOR));

    strcpy(td_ActDOR->pDOR_file, "blabla/blabla/file.icc");

    int path_lenght=strlen(td_ActDOR->pDOR_file);
    int i;
    char bla[4] = "rmc\0";
    printf("Stringul before: %s\n",path);
    for (i = 0; i < 3; i++)
    {
        Obiect->pDOR_file[path_lenght-(i+1)] = bla[i];
    }
    printf("Stringul after: %s\n",path);
    return 0;
}
Support Ukraine
  • 42,271
  • 4
  • 38
  • 63

1 Answers1

3

In your code, td_ActDOR is not a variable, (it's a type), Obiect is.

Change

  strcpy(td_ActDOR->pDOR_file, "blabla/blabla/file.icc");

to

 strcpy(Obiect->pDOR_file, "blabla/blabla/file.icc");

Same goes for strlen(td_ActDOR->pDOR_file);, too.

BLUEPIXY
  • 39,699
  • 7
  • 33
  • 70
Sourav Ghosh
  • 133,132
  • 16
  • 183
  • 261