LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-04-2009, 09:13 AM   #1
mortyg
LQ Newbie
 
Registered: Nov 2008
Distribution: Fedora 15
Posts: 5

Rep: Reputation: 0
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;

if(now.minutes == 60) { //next hour
now.minutes = 0;
++now.hour;

if(now.hour == 24) //midnight
now.hour = 0;

}
}
return now;
}
 
Old 07-04-2009, 10:48 AM   #2
norobro
Member
 
Registered: Feb 2006
Distribution: Debian Sid
Posts: 792

Rep: Reputation: 331Reputation: 331Reputation: 331Reputation: 331
Looks like you have a typo:
Code:
testTimes[i] = timeUpdate(testTimes[i]);
 
Old 07-04-2009, 11:24 AM   #3
Wim Sturkenboom
Senior Member
 
Registered: Jan 2005
Location: Roodepoort, South Africa
Distribution: Ubuntu 12.04, Antix19.3
Posts: 3,794

Rep: Reputation: 282Reputation: 282Reputation: 282
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.

Good luck with the coding.
 
Old 07-04-2009, 05:44 PM   #4
harry edwards
Member
 
Registered: Nov 2007
Location: Lincolnshire, UK
Distribution: CentOS, Fedora, and Suse
Posts: 365

Rep: Reputation: 48
The error you was presented was not that helpful: C can be cryptic at times. I recommend compiling with the -Wall switch i.e.

Code:
 cc -Wall test.c   -o test
Adding this in your case would have enabled you to spot the typographic error: you would have received a warning like:

Code:
 test.c:50: error: implicit declaration of function 'timeupDate'
Thus, pointing you to the real problem.

Last edited by harry edwards; 07-04-2009 at 05:45 PM.
 
Old 07-06-2009, 06:52 PM   #5
mortyg
LQ Newbie
 
Registered: Nov 2008
Distribution: Fedora 15
Posts: 5

Original Poster
Rep: Reputation: 0
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
 
Old 07-06-2009, 08:05 PM   #6
norobro
Member
 
Registered: Feb 2006
Distribution: Debian Sid
Posts: 792

Rep: Reputation: 331Reputation: 331Reputation: 331Reputation: 331
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
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
"Not a CODE" reference error perl v5.10.0, Deprecated assignment operation. skuletm Programming 3 03-12-2009 12:21 AM
"Volume has incompatible disk layout" Error... keita_mog Linux - Newbie 3 12-23-2008 06:23 PM
Thinkpad 600E modem: Mwavem incompatible with "modern" distro? wnor Linux - Laptop and Netbook 2 02-05-2007 08:10 AM
C code: error: incompatible types in assignment hedpe Programming 2 12-04-2006 10:30 AM
c++ incompatible types in assignment of `char*' f76 Programming 1 07-29-2005 01:42 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:51 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration