G
Gregc.
Hello
I am trying to get an understanding on strlen. From my understanding,
it takes a look at a string or single character array and returns the
length - the number of character in the string. When I try to apply it
to the following code:
#include <stdio.h>
#include <string.h>
const int MAX_FILENAME = 256;
void checkFilename (char *filename, char *extension)
{
char length[]=filename[MAX_FILENAME];
int size;
size = strlen(length);
return;
int main () {
char filename1 [MAX_FILENAME] = "testfile";
char filename2 [MAX_FILENAME] = "testfile.txt";
char filename3 [MAX_FILENAME] = "testfile.dat";
char extension [] = ".txt";
checkFilename (filename1, extension);
checkFilename (filename2, extension);
checkFilename (filename3, extension);
printf("1: %s\n", filename1);
printf("2: %s\n", filename2);
printf("3: %s\n", filename3);
}
I get " initializer fails to determine size of `length'" Could someone
direct me in the right direction. Please note, I'm not looking for the
answer, but more interested in getting an understanding of what is
going on.
Greg
I am trying to get an understanding on strlen. From my understanding,
it takes a look at a string or single character array and returns the
length - the number of character in the string. When I try to apply it
to the following code:
#include <stdio.h>
#include <string.h>
const int MAX_FILENAME = 256;
void checkFilename (char *filename, char *extension)
{
char length[]=filename[MAX_FILENAME];
int size;
size = strlen(length);
return;
int main () {
char filename1 [MAX_FILENAME] = "testfile";
char filename2 [MAX_FILENAME] = "testfile.txt";
char filename3 [MAX_FILENAME] = "testfile.dat";
char extension [] = ".txt";
checkFilename (filename1, extension);
checkFilename (filename2, extension);
checkFilename (filename3, extension);
printf("1: %s\n", filename1);
printf("2: %s\n", filename2);
printf("3: %s\n", filename3);
}
I get " initializer fails to determine size of `length'" Could someone
direct me in the right direction. Please note, I'm not looking for the
answer, but more interested in getting an understanding of what is
going on.
Greg