Hi all. Here's my problem. I have 2 character arrays that are being used to store strings. I want to compare array one with array 2 to see if they both have the same contents in them but it isnt working unfortunately. I this it has something to do with the trailing \n becasue array one gets its string by the user entereing a string via the scanf function. While array 2 uses the fget command red from a text file (it reads correctly from the text file). Here is what the code looks like (note, im writing this code now, its not the exact code im using as i dont have it with me, its at my uni).
Code:
#include <stdio.h>
FILE * fptr;
main()
{
fptr = fopen("linktofile.txt","r");
char test1[15] = "";
char test2[15] = "";
scanf("%s", test1);
fget(test2,15,fptr);
if (test1==test2){
printf("works");
}
}
sorry if my coding is bad, im very new to C, only started learning it yesterday. So can anyone see where im going wrong? My guess is with the if statement conditions.
Also is there a way to take a section of an array? For example, my code has 2 arrays both with a 15 index. Is there away for me to tell C that i only want to look at index 0 to 4. So i could do something like this
Code:
if (test1[0..4] ==test2[0..4])
Thanks a lot