#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2013
    Posts
    22
    Rep Power
    0

    Help to fix my code to asni


    hello to all
    i need your help ,i write this code (this is my main) and i compiler the code using this flag (under linux)

    gcc -Wall -ansi -pedantic -g match.c -o match

    this is the the outpot of the flag

    match.c:62:3: warning: ISO C90 forbids variable length array ‘Pattern’ [-Wvla]
    match.c:63:3: warning: ISO C90 forbids variable length array ‘Text’ [-Wvla]
    match.c:65:3: warning: format ‘%s’ expects argument of type ‘char *’, but argument 2 has type ‘char (*)[(long unsigned int)MAX]’ [-Wformat]
    match.c:67:3: warning: format ‘%s’ expects argument of type ‘char *’, but argument 2 has type ‘char (*)[(long unsigned int)MAX]’ [-Wformat]

    i know i problom on the arry length,i add the code :

    the rad line is the problom

    can someone help me the fix the problom that be at asni sintex

    Code:
     
    int main ()
    	{
        	const char * pattern;        /*const type of char and pointer  of arry that point on the pattern*/
        	const char * text;           /*const type of char and pointer  of arry that point on the text*/
        	const int MAX=20;            /*this is the max leng of the arry (text and pattern)*/
     
        	int len1;                    /*declaration of pramteat type int that hold the len of parrern*/ 
        	int len2;                    /*declaration of pramteat type int that hold the len of text*/
        	int d;                       /*declaration of pramteat that hold the return for mathc function*/
    		<font color="Red">char Pattern[MAX];</font>           /*declaration of the pattern arry */
    		<font color="Red">char Text[MAX]; </font>                /*declaration of the text arry*/
    		printf ("Enter the pattern:\n");  /*print to the user and ask the user to enter the pattern*/ 
    		<font color="Red">scanf ("%s",&Pattern); </font>                 /*scan the user input*/
    		printf ("Enter your text:\n");    /*print to the user and ask the user to enter the text*/ 
    		<font color="Red">scanf ("%s",&Text);  </font>                /*scan the user input*/
    		pattern=Pattern;                        /*move the addrese of the arry to pointer call pattern*/ 
    		text=Text;                          /*move the addrese of the arry to pointer call text*/
     
        	len1 = strlen (pattern);      /*save the len of pattern*/
        	len2 = strlen (text);         /*save the len of text*/
        	d = match (pattern, len1, text, len2);         /*send pramter to mathc ,the pattern pointer and text pointer and the leng of text and pattern*/
        	printf ("The low match is from the pattern %s and the text %s is %d.\n",             /*print to the user the best*/ 
                pattern, text, d);
        	return 0;
    }
  2. #2
  3. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,162
    Rep Power
    2222
    Define MAX as a macro; eg:
    Code:
    #define  MAX  20
    Pattern and Text, being array names, are already pointers. You do not need to use the address operator (&) on them, nor should you.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2013
    Posts
    22
    Rep Power
    0
    Pattern and Text are arrys to store the user input

    And the pattern and text are pointer to store the address to the arrys

    now i get this make: circular match <- match dependency dropped
  6. #4
  7. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,162
    Rep Power
    2222
    It looks like you completely missed what I was saying:
    Code:
            char Pattern[MAX];           /*declaration of the pattern arry */
            char Text[MAX];                 /*declaration of the text arry*/
            printf ("Enter the pattern:\n");  /*print to the user and ask the user to enter the pattern*/ 
            scanf ("%s",&Pattern);                  /*scan the user input*/
            printf ("Enter your text:\n");    /*print to the user and ask the user to enter the text*/ 
            scanf ("%s",&Text);                  /*scan the user input*/
    Why are you using the address operator in the scanfs for Pattern and Text? Since you declared Pattern and Text as arrays, they already are addresses. That is why you should not use the address operator with them. Instead, those scanf calls should look like this:
    Code:
            scanf ("%s",Pattern);                  /*scan the user input*/
            printf ("Enter your text:\n");    /*print to the user and ask the user to enter the text*/ 
            scanf ("%s",Text);                  /*scan the user input*/
    Please note that the ampersand (&) is not there.

    Now do you understand?

    Originally Posted by tamir yosef
    now i get this make: circular match <- match dependency dropped
    So then you changed something? What did you change?

    And since it appears to involve the match function, mightn't we need to know what that looks like?
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2013
    Posts
    22
    Rep Power
    0
    Yes i fix that thanks

    I will post the code i need to get to my home
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2013
    Posts
    22
    Rep Power
    0
    The problome only the makefile.

    whan i run the gcc -Wall -ansi -pedantic -g match.c -o match

    i dont get this massage

IMN logo majestic logo threadwatch logo seochat tools logo