Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > struct and pointer question

Reply
Thread Tools

struct and pointer question

 
 
Angel
Guest
Posts: n/a
 
      09-14-2012
On 2012-09-14, Bill Cunningham <(E-Mail Removed)> wrote:
>
> Yes! Yes! I hoped I could cross the usenet understanding barrier. This post
> is not directly related to the fread fwrite functions I just happened to use
> them so I can get used to them. Personally I like fgetc and fputc.


"get used to them"? Weren't you writing successful code with them all
the time?


--
"C provides a programmer with more than enough rope to hang himself.
C++ provides a firing squad, blindfold and last cigarette."
- seen in comp.lang.c
 
Reply With Quote
 
 
 
 
Bill Cunningham
Guest
Posts: n/a
 
      09-14-2012
Barry Schwarz wrote:
> Strange that you never post any of this successful code when asking a
> question. Or did I miss the smiley?


After a long struggle I seem to have caught onto them atleast well
enough to use them. I seem to IMO have caught onto something. Though my
loops need work.

Bill


 
Reply With Quote
 
 
 
 
Barry Schwarz
Guest
Posts: n/a
 
      09-15-2012
On Fri, 14 Sep 2012 19:07:51 -0400, "Bill Cunningham"
<(E-Mail Removed)> wrote:

snip

>This thread has nothing to do with fread or fwrite.


Then why are you repeatedly asking how to get those functions to work
with int*, char*, and size_t types?

Why don't you tell us what this thread is really about?

--
Remove del for email
 
Reply With Quote
 
Barry Schwarz
Guest
Posts: n/a
 
      09-15-2012
On Fri, 14 Sep 2012 19:13:22 -0400, "Bill Cunningham"
<(E-Mail Removed)> wrote:

>Ben Bacarisse wrote:
>
>> I read this about a dozen times and finally I think I worked it out.
>> The trouble is that you ask how do so what you think is needed when
>> that's not what's needed at all.
>>
>> I think you want a function that can read int one time and chars the
>> next. Other times you might want it to read size_ts or even something
>> else like doubles. To do that, you don't change the type of the
>> buffer, you change the size of the data being read.

>[snip]
>
>Problem solved. Thanks Much.


All evidence to the contrary.

--
Remove del for email
 
Reply With Quote
 
Bill Cunningham
Guest
Posts: n/a
 
      09-15-2012
Barry Schwarz wrote:

> Why don't you tell us what this thread is really about?


It's about passing a struct to a function called copi that calls on fread
fwrite. Indirectly fread and fwrite is being used so maybe it is in a away
about those 2 function's first parameter. Which is void *. This is the
generic pointer. That's why I have void *buf in my struct.

include stdio.h

int main(void) {
struct param p;
p.buf= /*Have no idea what to do now */

Now I can give up on this, or bring it to clc for help. I decided to do
that. I don't know how to code a pointer through a struct for differing
types of pointers like void * is for. I guess it doesn't matter in another
post I was told what type of buffer it is but the size of it so I consider
the question answered. But if you have anything to add I'm listening please
do.

Bill


 
Reply With Quote
 
Bill Cunningham
Guest
Posts: n/a
 
      09-15-2012
Angel wrote:

> "get used to them"? Weren't you writing successful code with them all
> the time?


Very funny. Now you know I struggled with those 2 functions for a long time.
My man pages not explaining in a way I could understand and not giving
examples I had to come to the group.

Bill


 
Reply With Quote
 
Bill Cunningham
Guest
Posts: n/a
 
      09-15-2012
Bill Cunningham wrote:
> Barry Schwarz wrote:
>
>> Why don't you tell us what this thread is really about?

>
> It's about passing a struct to a function called copi that calls on
> fread fwrite. Indirectly fread and fwrite is being used so maybe it
> is in a away about those 2 function's first parameter. Which is void
> *. This is the generic pointer. That's why I have void *buf in my
> struct.
> include stdio.h
>
> int main(void) {
> struct param p;
> p.buf= /*Have no idea what to do now */
>
> Now I can give up on this, or bring it to clc for help. I decided to
> do that. I don't know how to code a pointer through a struct for
> differing types of pointers like void * is for. I guess it doesn't
> matter in another post I was told what type of buffer it is but the
> size of it so I consider the question answered. But if you have
> anything to add I'm listening please do.
>
> Bill


Pardon me I want an array.

B


 
Reply With Quote
 
Ben Bacarisse
Guest
Posts: n/a
 
      09-15-2012
"Bill Cunningham" <(E-Mail Removed)> writes:

> Barry Schwarz wrote:
>
>> Why don't you tell us what this thread is really about?

>
> It's about passing a struct to a function called copi that calls on fread
> fwrite. Indirectly fread and fwrite is being used so maybe it is in a away
> about those 2 function's first parameter. Which is void *. This is the
> generic pointer. That's why I have void *buf in my struct.
>
> include stdio.h
>
> int main(void) {
> struct param p;
> p.buf= /*Have no idea what to do now */
>
> Now I can give up on this, or bring it to clc for help. I decided to do
> that. I don't know how to code a pointer through a struct for differing
> types of pointers like void * is for. I guess it doesn't matter in another
> post I was told what type of buffer it is but the size of it so I consider
> the question answered. But if you have anything to add I'm listening please
> do.


I think you missed the point. No one can help if we don't know what the
high-level goal is. Anyone who's guessed what your question means (I
have for example) knows that you should not be trying to do that, but
the right way to do it depends on what the program's high-level goal is.

Imagine this:

Q: I don't know how to alter the return type of a function.
CLC: You can't. What are you trying to do?
Q: I'm trying to alter the return type of a function.
CLC: No, what is the high-level goal?
Q: I want to process input where the data is either a number or a string
like "no data". I've written double get_data(); but I want main to
be able to alter that so get_data returns a char *.
CLC: Ah! You don't do that by "altering the return type". There are
several options...

I know exactly what you want the function to do. But I also know that's
not the right way to do anything in C so it would be pointless my
telling to how to do it. Whatever you program's objective it, there is
a better way than the one you are asking for advice about.

--
Ben.
 
Reply With Quote
 
Bill Cunningham
Guest
Posts: n/a
 
      09-15-2012
Ben Bacarisse wrote:

> I think you missed the point. No one can help if we don't know what
> the high-level goal is. Anyone who's guessed what your question
> means (I have for example) knows that you should not be trying to do
> that, but the right way to do it depends on what the program's
> high-level goal is.
>
> Imagine this:
>
> Q: I don't know how to alter the return type of a function.
> CLC: You can't. What are you trying to do?
> Q: I'm trying to alter the return type of a function.
> CLC: No, what is the high-level goal?
> Q: I want to process input where the data is either a number or a
> string like "no data". I've written double get_data(); but I want
> main to be able to alter that so get_data returns a char *.
> CLC: Ah! You don't do that by "altering the return type". There are
> several options...
>
> I know exactly what you want the function to do.


You hit the nail right on the head

> But I also know
> that's not the right way to do anything in C so it would be pointless
> my telling to how to do it. Whatever you program's objective it,
> there is a better way than the one you are asking for advice about.



 
Reply With Quote
 
Bill Cunningham
Guest
Posts: n/a
 
      09-15-2012
Barry Schwarz wrote:
> On Fri, 14 Sep 2012 19:13:22 -0400, "Bill Cunningham"
> <(E-Mail Removed)> wrote:
>
>> Ben Bacarisse wrote:
>>
>>> I read this about a dozen times and finally I think I worked it out.
>>> The trouble is that you ask how do so what you think is needed when
>>> that's not what's needed at all.
>>>
>>> I think you want a function that can read int one time and chars the
>>> next. Other times you might want it to read size_ts or even
>>> something else like doubles. To do that, you don't change the type
>>> of the buffer, you change the size of the data being read.

>> [snip]
>>
>> Problem solved. Thanks Much.

>
> All evidence to the contrary.


What do you mean? I'm a little squemish about the !feof(in) in the
while. I was told that loops should look for the positive not the negative.
Now that my mind is coming back. I can actually focus better now from
going down on clonazepam dosage. I'm going to break out kandr2 again. What
do you mean "all evidence to the contrary."

Bill


Bill


 
Reply With Quote
 
 
 
Reply

Thread Tools

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Struct pointer vs. struct array pointer aleksa C Programming 16 02-20-2013 08:20 PM
Can *common* struct-members of 2 different struct-types, that are thesame for the first common members, be accessed via pointer cast to either struct-type? John Reye C Programming 28 05-08-2012 12:24 AM
(: Pointer to struct withing pointer to struct :) Zero C Programming 16 11-19-2005 01:27 AM
passing pointer->struct->pointer->struct to function. .. ?? beetle C Programming 2 01-25-2005 06:08 PM
struct my_struct *p = (struct my_struct *)malloc(sizeof(struct my_struct)); Chris Fogelklou C Programming 36 04-20-2004 08:27 AM



Advertisments