In this case you might be using a pointer to some data structure that contains an integer, but you are not dereferencing the appropriate field; instead you are referencing the pointer and the compiler thinks you are trying to convert it to an integer. If you can share the offending program line, further help could be provided. Result is an int, integer s1 is a char const., a const pointer to char. You can't assign the value of a const char. to an integer (because they might not have the same size for example). You can however, as hinted by the warning, cast the value to the correct type to force it to stop warning you: result = (int)s1; ^ this casts the value of s1 to the int type.
In your first code you had char.a which got its value from a call to strcpy and at the end dbvalue returns the value of a. So you should have changed the type of dbvalue into char pointer.That would fix the type errors, but as ariasukma observed, it is not necessarily a correct fix to the overall problem because the pointer cannot point to a non-static local variable otherwise the caller might use a pointer to an object that no longer exists, but we see that the strcpy call involves rasrepdb and casrepdb, both of which are non-static local to the function.
Well, what I wanted to do was copy the information from the file into the structure, in good order.So, since the brand, version, etc of the cars is separated by 2 spaces, I tried that way.Major failure I guess.What do you suggest to fix it?Thank you so much for your answer, really appreciate it.EDIT:I just want to copy the file into my struct, while still assigning them to the correct places, so I can later go on the struct and easily get the brands, etc. Or would you recommend not using a struct at all, leaving the file open in read mode and then just do a function to search the strings for the brand version etc? Read up on fscanf. This is an input routine that does pattern matching.
And returns the number of successful conversions, so you can monitor it for failures.If that doesn't get it. Load the entire line as a single string using fgets, run through it looking for double spaces, replace one of the spaces with a coma or some other suitable deliminter. Then unleash sscanf on it.And if THAT doesn't get it, use strtok to break the thing into separate strings and extract the data that way.What you have is a very nasty problem, whatever programmer wrote that data file should probably be flipping burgers at some greasy spoon franchise.
Even if it's written for human readability a few comas would have still been a really good idea. Read up on fscanf. This is an input routine that does pattern matching. And returns the number of successful conversions, so you can monitor it for failures.If that doesn't get it. Load the entire line as a single string using fgets, run through it looking for double spaces, replace one of the spaces with a coma or some other suitable deliminter.
Then unleash sscanf on it.And if THAT doesn't get it, use strtok to break the thing into separate strings and extract the data that way.What you have is a very nasty problem, whatever programmer wrote that data file should probably be flipping burgers at some greasy spoon franchise. Even if it's written for human readability a few comas would have still been a really good idea.Data file was written by my C Programming teacher, this is basically my final work so I can pass the class. Code: // strstr gives a pointer to the next double space.
&chi is a pointer to where we are nowint length = strstr(&chi,' ') - χ// strncat rather than strncpy to preserve the NULL terminatorstrncat(car-Brand, ch+i, length);// advance past the string and the double spacei = i + 2 + length. Similar for other fieldsI don't actually think you should do that. I think you should use scanf.
But I think that the above might be roughly what you were trying to do, so thought I'd mention it. Code: // strstr gives a pointer to the next double space. &chi is a pointer to where we are nowint length = strstr(&chi,' ') - χ// strncat rather than strncpy to preserve the NULL terminatorstrncat(car-Brand, ch+i, length);// advance past the string and the double spacei = i + 2 + length.
Similar for other fieldsI don't actually think you should do that. I think you should use scanf. But I think that the above might be roughly what you were trying to do, so thought I'd mention it.Yes, that was what I was going for. Thanks so much for your post, made me realize my mistakes.I'll try and read up on scanf, see if I can change it to fit.Thanks.