Gudday all
The biggest error I get with my C programming is incompatible assignment types of various flavours. In this case it is strings.
Code:
char rptline[30]; //name of RPT file
const size_t size = 64;
struct _finddata_t fileData = {0};
// start a search for all files with an extension of "rpt"
searchHandle = _findfirst("*.rpt", &fileData);
// if the search started
if (searchHandle != -1) {
// print a banner
rptFile = fopen (rpt_file, "w+"); /* open data file "rptFile.dat" for writing */
do {
// print the file name
//puts(fileData.name);
printf("----- The .rpt file(s) are %s -----\n", fileData.name);
rptline = strcat(fileData.name, ".tmp");
printf("--- The tmp rpt file name is % ---\n", rptline);
//rename(fileData.name, )
fprintf(rptFile, "%s", fileData.name); /* write RPT file name to rptFile.dat file */
}
The fragment above shows my latest failure. I am trying to add the extension ".tmp " to a list of *.rpt files that I have found
e.g. I want to get 1.rpt.tmp, 2.rpt.tmp etc:
The problem occurs in the line
Code:
rptline = strcat(fileData.name, ".tmp");
The errror message is "error: incompatible types in assignment of `char*' to `char[30]' "
I assume that it does not accept that fileData.name is a string compatible with what strcat would expect. Yet in the line above viz.
Code:
printf("----- The .rpt file(s) are %s -----\n", fileData.name);
the program had no apparent trouble accepting fileData.name as a string.
Perhaps the initial assignment of fileData is a problem.
I find trying to sort what when pointers, contents of pointers etc: are to be used very confusing.
Ultimately all I want to do is rename existing *.rpt files to *.rpt.tmp. Maybe I am making a mountain out of a molehill?