x79, Thanks for sharing your thoughts and code.
I tested your "while" loop code and it gave the correct answer of 8 without giving me the 'size_t' warning. I also tested your "for" loop code but unfortunately it gave me compiler errors so I changed it to be more like your "while" loop (see below). After I changed it, it also gave the correct answer of 8 without the 'size_t' warning.
My code gives the size of the string which is 9 so it had to be reduced by 1 to give the correct answer of 8. Both your code and my code try to find the location where the string terminator is located. In your case, you test for the value of 0 pointed to by a pointer and in my case I test for the character that is '\0'. According to K&R's book "The C Programming Language" on page 35 it says, "The character constant '\0' represents the character with value zero. '\0' is often written instead of 0 to emphasize the character nature of some expressions." I've often thought about using 0 instead of '\0' as 0 is so much easier to type.
There are other ways to find the number of characters in a string. I found this example on page 36 in the K&R book "The C Programming Language":
char s[]="test.txt"; //I added ="test.txt" (the K&R example was a function returning the length of a string)
int i;
i = 0;
while ( s != '\0')
++i;
The "while" loop could also have been written using a "for" loop such as this:
for( i=0; s != '\0'; ++i);
The K&R "while" loop and the similar "for" loop gave me the correct answers of 8. Unfortunately, they also both gave me the 'size_t' warnings when I compiled them using my "ppj" file (previously posted). Now this is interesting. When I tested the "while" and "for" loops using a simple command prompt compiler that only has the -W2 option ("pocc -W2 Tests.c "), I did not receive the 'size_t' warning. What this means is that there is something else involved giving me 'size_t' warnings beside the -W2 "option". Perhaps the 'size_t' warning is given only when the program is compiled using 64 bits (my ppj file) and not given when compiled using 32 bits (my simple command prompt compiler). However, that doesn't explain why sometimes loop variables are not given the 'size_t' warning (Note: the example I use for no 'size_t' warning has an error, the second line should be "fputc(s2_temp,fptr2);" and not "fputc(s2_temp,fptr2);").
This is how I changed your "for" loop code:
int i = 0; // You should initialize variables before you use them for anything
char fptr1_name[]="test.txt";
char *ch; //I added this
for (ch = fptr1_name; *ch; ch++) ; //I removed "char" and added semicolon at end
//I removed the "if" statement
i = ch - fptr1_name; // address of ch minus address of fptr1_name