Why am I getting "structArray.c:22: error: incompatible types in assignment"?
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Why am I getting "structArray.c:22: error: incompatible types in assignment"?
Hi, I am very new to c programming, trying to learn by using, Stephen Kochan - Programming in C. I am having trouble getting a program (right out of the book, p. 183 to work. I have tried everything I know, but still cannot make 'er go. If someone could help, I would sure appreciate it.
struct time
{
int hour;
int minutes;
int seconds;
};
int main(void)
{
struct time timeUpDate(struct time now);
struct time testTimes[5] =
{ {11,59,59}, {12,0,0}, {1,29,59},
{23,59,59}, {19,12,27} };
int i;
for(i = 0; i < 5; i++) {
printf("Time is %.2i:%.2i:%.2i", testTimes[i].hour,
testTimes[i].minutes, testTimes[i].seconds);
testTimes[i] = timeUpdate(testTimes[i]);
printf("...one second later it's %.2i:%.2i:%.2i\n",
testTimes[i].hour, testTimes[i].minutes, testTimes[i].seconds);
}
return 0;
}
//funtion to update the time by one second
struct time timeUpDate(struct time now)
{
++now.seconds;
if(now.seconds == 60) { //next minute
now.seconds = 0;
++now.minutes;
No anser to the question but please use code tags the next time when posting code. It will preserve the indentations and therefore makes it easier to read.
It will also make it easier if you highlight the line with error so we don't have to guess.
I have to admit my face is a little red right now, I went over that until I thought I would go blind. Thank you all for your responses, they have all helped me, later mortyg
No reason to be embarrassed. I didn't spot the typo reviewing your post. I have been coding in C++ lately and after copying your code to my machine, out of habit I used g++ (that's my story and I'm sticking to it) and it spit out a much more informative error message:
Code:
error: ‘timeUpdate’ was not declared in this scope
I think a quote from Douglas Adams "So Long, and Thanks for All the Fish" is apropos here:
Quote:
See first, think later, then test. But always see first. Otherwise you will only see what you were expecting.
I know a lot of times I see what I'm expecting, especially when I am looking at my own code.
Norm
Last edited by norobro; 07-08-2009 at 01:23 PM.
Reason: corrected typo
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.