How do i do this?
Im new to C and i need to do this on an assignment im working on.
Any help is much appreciated.
How do i do this?
Im new to C and i need to do this on an assignment im working on.
Any help is much appreciated.
strcmp, look it up.
its in string.h
vous pouvez declarer une chaine de caractere dans un tableau de la facon suivante
#define max 10000
char t[max];
puis lire de cette facon
scanf("%c",&t[]);
la comparaison sera faite dans une boucle repeter caractere par caractere
je croit que ca c'est tre facile alors faite le vite
Hello raiden,
I also recommend strcmp(), let me write an example:
Code 1.1: Example of using strcmp()Code:#include <string.h> #include <stdlib.h> int main() { char *s1 = "Hello"; char *s2 = "Hello!"; char *s2 = "Hello"; if( !strcmp(s1, s2) ) printf("Match!"); else printf("Strings did not match"); if( strcmp(s1, s3) == 0 ) // used ! last time to indicate 0 printf("Match!"); else printf("Strings did not match"); return 0; }
What I did here was make three variables, *s1, *s2, and *s3. s1 and s3 are the same, while s2 varies from the group. strcmp returns 0 if the strings match, else > 1 depending on the difference of the two strings.
It's quite a simple implementation, so either way you use it "== 0" or "!" (which indicates 0) will still produce the same result. I personally like the "!" myself, but every programmer has his/her ways of coding format and style.
Hope this helped,
- Stack Overflow
Segmentation Fault: I am an error in which a running program attempts to access memory not allocated to it and core dumps with a segmentation violation error. This is often caused by improper usage of pointers, attempts to access a non-existent or read-only physical memory address, re-use of memory if freed within the same scope, de-referencing a null pointer, or (in C) inadvertently using a non-pointer variable as a pointer.