On 7/16/05, Vikas S <[EMAIL PROTECTED]> wrote:
>
> Thanks, This is a workable solution.
> But the issue is I've some 100+ structures. So, writing
> a if or case is going to be difficult.
Another way I can suggest would be passing the file name at command prompt.
./size foo.txt
foo.txt should c
Vika,
Perhaps you can add a sizeof field to your structures and query it?
struct s{
int a;
float b;
int mysize = sizeof(s);
};
int function(struct *s){
return s->mysize;
}
Pardon my code, its more like psuedocode than anything that will compile, but
the idea is there. The probl
> Thanks, This is a workable solution.
> But the issue is I've some 100+ structures. So, writing
> a if or case is going to be difficult.
>
> b) Yes. I want to pass a structure name. ie, make sizeof
> accept a variable.
You can't do this in C, but you might be able to achieve something
similar us
On 7/16/05, Vikas S <[EMAIL PROTECTED]> wrote:
>
> Thanks, This is a workable solution.
> But the issue is I've some 100+ structures. So, writing
> a if or case is going to be difficult.
Wow, that's a lot of work :-)
> a) You are right.
> b) Yes. I want to pass a structure name. ie, make sizeof
Thanks, This is a workable solution.
But the issue is I've some 100+ structures. So, writing
a if or case is going to be difficult.
a) You are right.
b) Yes. I want to pass a structure name. ie, make sizeof
accept a variable.
Is this impossible?
Thanks,
Vikas
--- Steve Graegert <[EMAIL PROTEC
On 7/15/05, Vikas S <[EMAIL PROTECTED]> wrote:
>
> I guess I was not clear. Say, we have two structures.
>
> str1 {int x, char y} and str2 {int x, char *y};
OK...
> printf(sizeof(struct str1)); will give proper output. ie memory occupied
> by str1.
...reasonable...
> What I want is, instead
I guess I was not clear. Say, we have two structures.
str1 {int x, char y} and str2 {int x, char *y};
printf(sizeof(struct str1)); will give proper output. ie memory occupied
by str1.
What I want is, instead of hard-coding str1 etc., I want to find
the size of structure which I will give as 1st
strlen on a null pointer will segfault...
if arc is 1 then argv[0] will contain a pointer to an array of char
if arc is 2 then argv[1] (the users first argument) will contain an
array of char..
so don't forget to check the number of arguments ..
On 7/15/05, Vadiraj <[EMAIL PROTECTED]> wrote:
> Vik
Vikas,
On 7/15/05, Vikas S <[EMAIL PROTECTED]> wrote:
> I want to find out the size of a structure which the user will give as an
> argument
> as follows.
>
> #include <> -- All includes..
> ..
> main(int arc, char *argv[])
argv is a charecter pointer . You cannot pass struct * as an
arguem