[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.c

Re: prototypes and struct quest.

Bill Cunningham

2/9/2011 12:22:00 AM

Ok I tried this code and it wouldn't compile. The error says line 8
incompatable types. I am probably looking right at it. I think I might
rewrite and use pointers so I know I can get this idea to work. But I want
to post what I tried. This is all C89.


#include <stdio.h>
#include <stdlib.h>

#define TYPE unsigned int

struct stk {
TYPE volume;
TYPE price;
TYPE date[6];
};

struct stk swrite(struct stk name);
struct stk sread(struct stk name);

struct stk sread(struct stk name)
{
TYPE date[6];
TYPE price;
TYPE volume;
date = name.date;
volume = name.volume;
price = name.price;
}

B


13 Answers

Tom St Denis

2/9/2011 11:35:00 AM

0

On Feb 8, 7:22 pm, "Bill Cunningham" <nos...@nspam.invalid> wrote:
>     Ok I tried this code and it wouldn't compile. The error says line 8
> incompatable types. I am probably looking right at it. I think I might
> rewrite and use pointers so I know I can get this idea to work. But I want
> to post what I tried. This is all C89.
>
> #include <stdio.h>
> #include <stdlib.h>
>
> #define TYPE unsigned int
>
> struct stk {
>     TYPE volume;
>     TYPE price;
>     TYPE date[6];
>
> };
>
> struct stk swrite(struct stk name);
> struct stk sread(struct stk name);
>
> struct stk sread(struct stk name)
> {
>     TYPE date[6];
>     TYPE price;
>     TYPE volume;
>     date = name.date;
>     volume = name.volume;
>     price = name.price;
>
> }

I don't get what this function is supposed to accomplish. I was
wondering though, do you think before you post? Or do you enter some
zen-like thought-free state before posting?

Your "read" function copies out members of a structure, then proceeds
to return to the caller without an actual return value. What is that
supposed to accomplish?

It would also help to get the actual output from the compiler as
opposed to your filtered rendering of it. Though, what would actually
really help is for you to plan out what your program is supposed to do
BEFORE you write it.

Tom

Bill Cunningham

2/9/2011 12:13:00 PM

0

Tom St Denis wrote:
> On Feb 8, 7:22 pm, "Bill Cunningham" <nos...@nspam.invalid> wrote:
>> Ok I tried this code and it wouldn't compile. The error says line 8
>> incompatable types. I am probably looking right at it. I think I
>> might rewrite and use pointers so I know I can get this idea to
>> work. But I want to post what I tried. This is all C89.
>>
>> #include <stdio.h>
>> #include <stdlib.h>
>>
>> #define TYPE unsigned int
>>
>> struct stk {
>> TYPE volume;
>> TYPE price;
>> TYPE date[6];
>>
>> };
>>
>> struct stk swrite(struct stk name);
>> struct stk sread(struct stk name);
>>
>> struct stk sread(struct stk name)
>> {
>> TYPE date[6];
>> TYPE price;
>> TYPE volume;
>> date = name.date;
>> volume = name.volume;
>> price = name.price;
>>
>> }
>
> I don't get what this function is supposed to accomplish. I was
> wondering though, do you think before you post? Or do you enter some
> zen-like thought-free state before posting?
>
> Your "read" function copies out members of a structure, then proceeds
> to return to the caller without an actual return value. What is that
> supposed to accomplish?
>
> It would also help to get the actual output from the compiler as
> opposed to your filtered rendering of it. Though, what would actually
> really help is for you to plan out what your program is supposed to do
> BEFORE you write it.
>
> Tom

sread is supposed to take as it's parameter one value at a time and and put
it into the struct stk type called name. I obviously don't remember how to
do it correctly or neverlearned right. Hence my inexperience with structs. I
do believe I can do this with pointers though.

struct stk name;

name.date=020811;
name.price=20.00; //In USD.
name.volume=232987;

This is how I would load a struct. Now swrite is supposed to do that for
me. Instead of typing all this manually, I want to pass to swrite data and
have swrite write it into the struct. sread would fetch it back. Simple
concept. I don't know for sure how to code it.

B


Bill Cunningham

2/9/2011 12:15:00 PM

0

Bill Cunningham wrote:
> Tom St Denis wrote:
>> On Feb 8, 7:22 pm, "Bill Cunningham" <nos...@nspam.invalid> wrote:
>>> Ok I tried this code and it wouldn't compile. The error says line 8
>>> incompatable types. I am probably looking right at it. I think I
>>> might rewrite and use pointers so I know I can get this idea to
>>> work. But I want to post what I tried. This is all C89.
>>>
>>> #include <stdio.h>
>>> #include <stdlib.h>
>>>
>>> #define TYPE unsigned int
>>>
>>> struct stk {
>>> TYPE volume;
>>> TYPE price;
>>> TYPE date[6];
>>>
>>> };
>>>
>>> struct stk swrite(struct stk name);
>>> struct stk sread(struct stk name);
>>>
>>> struct stk sread(struct stk name)
>>> {
>>> TYPE date[6];
>>> TYPE price;
>>> TYPE volume;
>>> date = name.date;
>>> volume = name.volume;
>>> price = name.price;
>>>
>>> }
>>
>> I don't get what this function is supposed to accomplish. I was
>> wondering though, do you think before you post? Or do you enter some
>> zen-like thought-free state before posting?
>>
>> Your "read" function copies out members of a structure, then proceeds
>> to return to the caller without an actual return value. What is that
>> supposed to accomplish?
>>
>> It would also help to get the actual output from the compiler as
>> opposed to your filtered rendering of it. Though, what would
>> actually really help is for you to plan out what your program is
>> supposed to do BEFORE you write it.
>>
>> Tom
>
> sread is supposed to take as it's parameter one value at a time and
> and put it into the struct stk type called name. I obviously don't
> remember how to do it correctly or neverlearned right. Hence my
> inexperience with structs. I do believe I can do this with pointers
> though.
> struct stk name;
>
> name.date=020811;
> name.price=20.00; //In USD.
> name.volume=232987;
>
> This is how I would load a struct. Now swrite is supposed to do that
> for me. Instead of typing all this manually, I want to pass to swrite
> data and have swrite write it into the struct. sread would fetch it
> back. Simple concept. I don't know for sure how to code it.
>
> B

swrite() should write to struct. sread() read the data from it. Yes that's
right.


Tom St Denis

2/9/2011 5:12:00 PM

0

On Feb 9, 7:12 am, "Bill Cunningham" <nos...@nspam.invalid> wrote:
> sread is supposed to take as it's parameter one value at a time and and put
> it into the struct stk type called name. I obviously don't remember how to
> do it correctly or neverlearned right. Hence my inexperience with structs.. I
> do believe I can do this with pointers though.

Except that in your example you provided as input a struct and
returned a struct, then your mock code copied elements out of a
struct. That's clearly not what you're trying to do.

What I don't get is why you bother trolling clc. If you were actually
trying to accomplish something you'd organize your thoughts and work a
lot better than you do. Instead, you just post random snippets of
whatever goof off material springs to mind.

> struct stk name;
>
> name.date=020811;
> name.price=20.00; //In USD.

You're sticking a floating point value in an unsigned int. Really?

> name.volume=232987;
>
>  This is how I would load a struct. Now swrite is supposed to do that for
> me. Instead of typing all this manually, I want to pass to swrite data and
> have swrite write it into the struct. sread would fetch it back. Simple
> concept. I don't know for sure how to code it.

Writing it should be easy, e.g.

void swrite(struct stk *dst, TYPE date, TYPE price, TYPE volume);

Or even

struct stk swrite(TYPE date, TYPE price, TYPE volume);

As for sread, that's a bit harder since you're trying to read out the
elements serially you either need multiple pointers like

void sread(struct stk *src, TYPE *date, TYPE *price, TYPE *volume);

Or you need to specify WHICH member you want to return. But what you
REALLY need to do is stop trolling USENET.

Tom

Bill Cunningham

2/9/2011 5:57:00 PM

0

Tom St Denis wrote:
> On Feb 9, 7:12 am, "Bill Cunningham" <nos...@nspam.invalid> wrote:
>> sread is supposed to take as it's parameter one value at a time and
>> and put it into the struct stk type called name. I obviously don't
>> remember how to do it correctly or neverlearned right. Hence my
>> inexperience with structs. I do believe I can do this with pointers
>> though.
>
> Except that in your example you provided as input a struct and
> returned a struct, then your mock code copied elements out of a
> struct. That's clearly not what you're trying to do.
>
> What I don't get is why you bother trolling clc. If you were actually
> trying to accomplish something you'd organize your thoughts and work a
> lot better than you do. Instead, you just post random snippets of
> whatever goof off material springs to mind.
>
>> struct stk name;
>>
>> name.date=020811;
>> name.price=20.00; //In USD.
>
> You're sticking a floating point value in an unsigned int. Really?
>
>> name.volume=232987;
>>
>> This is how I would load a struct. Now swrite is supposed to do that
>> for me. Instead of typing all this manually, I want to pass to
>> swrite data and have swrite write it into the struct. sread would
>> fetch it back. Simple concept. I don't know for sure how to code it.
>
> Writing it should be easy, e.g.
>
> void swrite(struct stk *dst, TYPE date, TYPE price, TYPE volume);
>
> Or even
>
> struct stk swrite(TYPE date, TYPE price, TYPE volume);
>
> As for sread, that's a bit harder since you're trying to read out the
> elements serially you either need multiple pointers like
>
> void sread(struct stk *src, TYPE *date, TYPE *price, TYPE *volume);
>
> Or you need to specify WHICH member you want to return. But what you
> REALLY need to do is stop trolling USENET.
>
> Tom

I didn't know you were xenophobic Tom. If so why did you even respond to
my post. Well I thought I might need pointers somewhere I think your
examples have indeed helped me though so thanks.

Bill


Tom St Denis

2/9/2011 6:02:00 PM

0

On Feb 9, 12:57 pm, "Bill Cunningham" <nos...@nspam.invalid> wrote:
>     I didn't know you were xenophobic Tom. If so why did you even respond to
> my post. Well I thought I might need pointers somewhere I think your
> examples have indeed helped me though so thanks.

I don't think that word means what you think it means...

I don't mind answering questions it's just you specifically are a pain
in that you don't ever think before you post. Your "example" programs
here [which aren't even complete apps] usually exhibit the lack of
effort on your part. Let me show you how your posts come across

---
BillS msg:

Hey guys I was trying to write a Quake 3D like engine, here's what I
have so far

struct potato { int gun; } = 5;

But so far I don't see any cool 3d models on the screen yet? What
gives?
---

Then two weeks later...

---
BillS msg:

Hey guys I was trying to write a program to calculate the mean density
of doritos. Here's what I have so far:

#define RADIUS = PI
RADIUS dorito = 3;

But so far it doesn't tell me what I want. Help?
---

etc and so on...You're a troll. And again I'm only replying because
I'm bored on lunch...

Tom

Bill Cunningham

2/9/2011 6:50:00 PM

0

Tom St Denis wrote:

[...]

> I don't mind answering questions it's just you specifically are a pain
> in that you don't ever think before you post.

Do you realize how hard it is for me to "think" as you call it. I have
lived in the same small town for my life and get lost going somewhere I go
everyday[by driving]. I see a psychiatrist MD and now a PhD in pschology to
trim down medications. I have been trimming some down slowly. Sometimes I
don't know exactly what I'm saying or even moreso explaining it coherently.
So I do understand I might be hard to understand. I have been working to
understand things more clearly before I jump in and post to clc. I come
across to some I know personally as "lazy".

Xenophobe: Usenet. Someone always looking for strange motives to others
posts. Worrying and fearing that someone might be doing something [like
trolling] and being so overly concerned they might "lose sleep" over
someone.

Bill


Tom St Denis

2/9/2011 6:55:00 PM

0

On Feb 9, 1:49 pm, "Bill Cunningham" <nos...@nspam.invalid> wrote:
> Tom St Denis wrote:
>
> [...]
>
> > I don't mind answering questions it's just you specifically are a pain
> > in that you don't ever think before you post.
>
>     Do you realize how hard it is for me to "think" as you call it. I have
> lived in the same small town for my life and get lost going somewhere I go
> everyday[by driving]. I see a psychiatrist MD and now a PhD in pschology to
> trim down medications. I have been trimming some down slowly. Sometimes I
> don't know exactly what I'm saying or even moreso explaining it coherently.
> So I do understand I might be hard to understand. I have been working to
> understand things more clearly before I jump in and post to clc. I come
> across to some I know personally as "lazy".

Not to sound like too much of a cunt, but if you really do have a
disability that prevents you from being able to learn a technical
trade like programming why not just move on? It's like a blind man
"trying really hard" to be sharp shooter...

> Xenophobe: Usenet. Someone always looking for strange motives to others
> posts. Worrying and fearing that someone might be doing something [like
> trolling] and being so overly concerned they might "lose sleep" over
> someone.

I lose sleep over nothing that happens in USENET. I only replied to
you because all the other threads seemed well answered and I hadn't
picked a fight yet today. Plus I've seen your worthless posts before
and I felt like reminding you of how little you're contributing.

Tom

Bill Cunningham

2/9/2011 7:27:00 PM

0

Tom St Denis wrote:

[...]

> I lose sleep over nothing that happens in USENET. I only replied to
> you because all the other threads seemed well answered and I hadn't
> picked a fight yet today. Plus I've seen your worthless posts before
> and I felt like reminding you of how little you're contributing.
>
> Tom

I'm not quite sure by what you mean by "...how little you're
contributing." I do lurk clc from time to time and I have taken some time
off to look at things and thought about whether I wanted to tackle C or
something else. I don't feel like I can contribute a wholelot to anyone else
starting C really because I don't feel worthy of interfering in the words of
those who understand much more than I.

B


gordonb.bapi9

2/10/2011 7:58:00 AM

0

> sread is supposed to take as it's parameter one value at a time and and put
> it into the struct stk type called name.

Then it obviously doesn't *READ*. Why didn't you name it spack()? or
sload()?


> This is how I would load a struct. Now swrite is supposed to do that for
> me. Instead of typing all this manually, I want to pass to swrite data and
> have swrite write it into the struct.

Isn't that what you just decided sread() does?

>sread would fetch it back.

This contradicts what you said sread() is supposed to do above.

>Simple
> concept. I don't know for sure how to code it.

Try defining which function is supposed to do what, and give functions
reasonable names describing what they do, before trying to write code
for them.