linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ron Michael Khu <ronkhu@ntsp.nec.co.jp>
Cc: Lejanson Go <lejanson@ntsp.nec.co.jp>, Fabio <fabio@crearium.com>,
	linux-c-programming@vger.kernel.org
Subject: Re: Dinamic array allocation
Date: Tue, 26 Oct 2004 13:15:28 +0800	[thread overview]
Message-ID: <417DDD70.3060605@hq.ntsp.nec.co.jp> (raw)
In-Reply-To: <417DD9BA.8040009@hq.ntsp.nec.co.jp>

This is Mr. Fabio's code:

main(int argc, char *argv[])
{
   char *Array[];
   int length,i;
   char foo[10]="bar";
   length = strlen(foo) + atoi(argv[1]);
   Array = malloc(length)
   for(i=;i<length;i++)
       Array[i]="a";
}

Fabio, ur trying to create an array of char ptrs.....
so u  need to modify the way u mallocs space...
   Array = malloc(length)
is only applicable if u have defined Array
as char *Array;

(and u need to initialize "i" just in case... im not
sure about the default value of ints)



Lejanson C. Go wrote:

> I hope i am correct. :D
>
> ptr = (char *) malloc (strtol(argv[1])+strlen(foo));
>
>
> Ron Michael Khu wrote:
>
>> arvp[1] is string....
>> u should convert it to a numeric type via atoi() or strtol()....
>>
>> =)
>>
>> Fabio wrote:
>>
>>> Hi.
>>>
>>> I am programming a C code that gets argv[1] as the lenght of an 
>>> array that is the copy of an array plus more data.
>>>
>>> So, the appication runs as: ./a.out 100
>>>
>>> It create an array of 100 bytes and adds a static defined array plus 
>>> more data, like:
>>>
>>> char *foo[5]="bar"
>>> main(int argc, char *argv[])
>>> {
>>>    char *Ptr[];
>>>    Ptr = malloc( argv[1]+strlen(foo));
>>>    ....
>>> }
>>>
>>> Makes sense? guess no.
>>>
>>> Any suggestion is welcome.
>>>
>>> thanks in advance
>>> -
>>> To unsubscribe from this list: send the line "unsubscribe 
>>> linux-c-programming" in
>>> the body of a message to majordomo@vger.kernel.org
>>> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>>>
>>>
>>
>> -
>> To unsubscribe from this list: send the line "unsubscribe 
>> linux-c-programming" in
>> the body of a message to majordomo@vger.kernel.org
>> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>>
>>
>
>
>


  reply	other threads:[~2004-10-26  5:15 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-10-26  3:03 Dinamic array allocation Fabio
2004-10-26  4:09 ` Ron Michael Khu
2004-10-26  4:12   ` Ron Michael Khu
2004-10-26  4:59   ` Lejanson C. Go
2004-10-26  5:15     ` Ron Michael Khu [this message]
2004-10-26  5:51 ` Glynn Clements

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=417DDD70.3060605@hq.ntsp.nec.co.jp \
    --to=ronkhu@ntsp.nec.co.jp \
    --cc=fabio@crearium.com \
    --cc=lejanson@ntsp.nec.co.jp \
    --cc=linux-c-programming@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).