Thread: compiler error

  1. #1
    In my head happyclown's Avatar
    Join Date
    Dec 2008
    Location
    In my head
    Posts
    391

    compiler error

    Hi all. Here's some partial code. I would love to post the whole code, but I am tired of spending 10 or more minutes after making a post
    trying to format the text to fit the forum screen.

    (Sorry, I've already spent 15 minute so far just editing this post), trying to stop the lines from running off the right edge of the screen. I give up.

    If I have this:

    Code:
    struct data {
            int month, day, year, hour, minute;
            char string1[2+1];
            int number1, number2;
            char string2[FILENAMELENGTH];
            char stringstorage[LINELENGTH];		// Used to store strings from file
    		char string3[FILENAMELENGTH];	// filenames that contain the search string
        } LineData[NUMBEROFFILES];
    
    for( counter1 = BEGINNINGOFHTMLLIST; counter1 < (lastfilenumber - 1); counter1++) 
    	{	
    		if((p_openfile = fopen(LineData[counter1].string2, "rt")) == NULL)
    		{
    			perror("\nError opening file");
    			exit(EXIT_FAILURE);
    		}
    
    		p_line = malloc(FILELINELENGTH * sizeof(char));
    
    		while((fgets(p_line, FILELINELENGTH, p_openfile) != NULL))
    		{
    		counter2 = 0;
    		if((p_searchstring = strstr(p_line,p_searchtext)) != NULL)
    			{
    				LineData[counter2].string3 = LineData[counter1].string2;  <=== compiler error(line 95)===
    				break;
    			}
    
    			counter2++;
    			free(p_line);
    			p_line = malloc(FILELINELENGTH * sizeof(char));
    			fclose(p_openfile);
    		}
    	}
    I get the following compiler error:
    Code:
    (95) : error C2106: '=' : left operand must be l-value
    I can't see what's wrong with it, and I don't understand VC++ 2008's explanation of what an l-value is:
    Code:
    Expressions that refer to memory locations are called "l-value" expressions. An l-value represents a storage
    region's "locator" value, or a "left" value, implying that it can appear on the left of the equal sign (=). 
    L-values are often identifiers. Expressions referring to modifiable locations are called "modifiable l-values." 
    A modifiable l-value cannot have an array type, an incomplete type, or a type with the const attribute. 
    For structures and unions to be modifiable l-values, they must not have any members with the const attribute. 
    The name of the identifier denotes a storage location, while the value of the variable is the value
     stored at that location. 
    
    An identifier is a modifiable l-value if it refers to a memory location and if its type is arithmetic, structure, union, or pointer. For example, if ptr is a pointer to a storage region, then *ptr is a modifiable l-value that designates the storage region to which ptr points. 
    
    Any of the following C expressions can be l-value expressions: 
    
    An identifier of integral, floating, pointer, structure, or union type 
    
    A subscript ([ ]) expression that does not evaluate to an array 
    
    A member-selection expression (–> or .) 
    
    A unary-indirection (*) expression that does not refer to an array 
    
    An l-value expression in parentheses 
    
    A const object (a nonmodifiable l-value) 
    
    The term "r-value" is sometimes used to describe the value of an expression and to distinguish it from an l-value. All l-values are r-values but not all r-values are l-values. 
    
    Microsoft Specific 
    
    Microsoft C includes an extension to the ANSI C standard that allows casts of l-values to be used as l-values, as long as the size of the object is not lengthened through the cast. (See Type-Cast Conversions for more information.) The following example illustrates this feature: 
    
      Copy Code 
    char *p ;
    short  i;
    long l;
    
    (long *) p = &l ;       /* Legal cast   */
    (long) i = l ;          /* Illegal cast */
     
    
    The default for Microsoft C is that the Microsoft extensions are enabled. Use the /Za compiler option to disable these extensions.
    Thanks in advance for any and all help.
    Last edited by happyclown; 01-25-2009 at 03:20 AM.
    OS: Linux Mint 13(Maya) LTS 64 bit.

  2. #2
    In my head happyclown's Avatar
    Join Date
    Dec 2008
    Location
    In my head
    Posts
    391
    Bugger that, here's the entire code, if it is of any use to anyone.
    Code:
    #define _CRT_SECURE_NO_WARNINGS // To turn off VC++ 2008 deprecation warnings
    
    #include <stdlib.h>
    #include <stdio.h>
    #include <string.h>
    
    #define NUMBEROFFILES 1500		// maximum number of files in the directory listing
    #define LINELENGTH 150			// length of a line in the directory listing
    #define FILENAMELENGTH 40		// length of an .html file
    #define BEGINNINGOFHTMLLIST 5	// first html file in directory list
    #define FILELINELENGTH 1000		// lengh of a line in an html file
    
    int main( void )
    { 
        int lastfilenumber;
        FILE *p_openfile;
    	char *p_comma;				// used to test for occurence of a comma in a line of the directory listing
    	char *p_line;				// stores successive lines from a file from the directory listing
        int  counter1, counter2;
    	char *p_searchstring; 
    	char *p_searchtext = "every";		// string to search for in a file
    
    	struct data {
            int month, day, year, hour, minute;
            char string1[2+1];
    		int number1, number2;
            char string2[FILENAMELENGTH];
            char stringstorage[LINELENGTH];		// Used to store strings from file
    		char string3[FILENAMELENGTH];		// filenames that contain the search string
        } LineData[NUMBEROFFILES];
    
        // Get a list of files in the directory "testwebsite", and redirect the
        // output to a file called "directorylisting.txt". */
    
    	system("dir c:\\testwebsite\\*.html > directorylisting.txt");
    
        // Test to see that the file "directorylisting.txt" can be opened for reading.
    
        if( (p_openfile = fopen("directorylisting.txt", "rt")) == NULL)
        {
            perror("directorylisting.txt");
            exit( EXIT_FAILURE );
        }
    
        // Copy the lines in the file to the array 
    
        counter1 = 0;
    
        while((fgets(LineData[counter1].stringstorage, LINELENGTH, p_openfile) != NULL) && (counter1 < NUMBEROFFILES))
        {
    		lastfilenumber = counter1;
            counter1++;	
        }
    
        fclose(p_openfile);
    
    	// Process the string, and store data items in the structure members
    
    	for( counter1 = BEGINNINGOFHTMLLIST; counter1 < lastfilenumber; counter1++)
    	{
    		if( (p_comma = strchr( LineData[counter1].stringstorage, ',')) != NULL )
    		{
    			sscanf(LineData[counter1].stringstorage, "%d%/%d/%d %d:%d %s %d,%d %s", &LineData[counter1].month,
                               &LineData[counter1].day, &LineData[counter1].year, &LineData[counter1].hour,
    						   &LineData[counter1].minute, LineData[counter1].string1, &LineData[counter1].number1,							&LineData[counter1].number2, &LineData[counter1].string2);
    		}
    
    		if( (p_comma = strchr( LineData[counter1].stringstorage, ',')) == NULL )
    		{
    			sscanf(LineData[counter1].stringstorage, "%d%/%d/%d %d:%d %s %d %s", &LineData[counter1].month,
                            &LineData[counter1].day, &LineData[counter1].year, &LineData[counter1].hour,
    						&LineData[counter1].minute, LineData[counter1].string1, &LineData[counter1].number1, 
    						&LineData[counter1].string2);
    		}
    	}
    
    	// open up a file, search for p_searchtext, if it exists, store filename(LineData[counter1].string2) in
    	// LineData[counter2].string3
    
    	for( counter1 = BEGINNINGOFHTMLLIST; counter1 < (lastfilenumber - 1); counter1++) 
    	{	
    		if((p_openfile = fopen(LineData[counter1].string2, "rt")) == NULL)
    		{
    			perror("\nError opening file");
    			exit(EXIT_FAILURE);
    		}
    
    		p_line = malloc(FILELINELENGTH * sizeof(char));
    
    		while((fgets(p_line, FILELINELENGTH, p_openfile) != NULL))
    		{
    			counter2 = 0;
    			if((p_searchstring = strstr(p_line,p_searchtext)) != NULL)
    			{
    				LineData[counter2].string3 = LineData[counter1].string2;  
    				break;
    			}
    
    			counter2++;
    			free(p_line);
    			p_line = malloc(FILELINELENGTH * sizeof(char));
    			fclose(p_openfile);
    		}
    	}
    
        return 0;
    }
    EDIT: What I am trying to do with that while loop is to use fgets to put a string in a file into a pointer. Then search for another string within the first string. Then if the string is found in that file, copy the filename to LineData[counter2].string3(a member of the structure).
    Last edited by happyclown; 01-25-2009 at 03:21 AM.
    OS: Linux Mint 13(Maya) LTS 64 bit.

  3. #3
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    You cannot assign to an array in C.
    You will have to manually copy every element over or use memcpy.
    Oh and instead of putting code tags around explanations, use [quote][/quote] tags.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    The short version of an l-value is "something that can be assigned to" (yes, I realize I'm cribbing from the explanation). So: a thing, a member of an array. No arrays themselves, and no consts, and no results of operations (so x+y is not an lvalue).

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how do you resolve this error?
    By -EquinoX- in forum C Programming
    Replies: 32
    Last Post: 11-05-2008, 04:35 PM
  2. Making C DLL using MSVC++ 2005
    By chico1st in forum C Programming
    Replies: 26
    Last Post: 05-28-2008, 01:17 PM
  3. error: template with C linkage
    By michaels-r in forum C++ Programming
    Replies: 3
    Last Post: 05-17-2006, 08:11 AM
  4. load gif into program
    By willc0de4food in forum Windows Programming
    Replies: 14
    Last Post: 01-11-2006, 10:43 AM
  5. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM