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 11-14-2007, 05:32 AM   #1
aaabhish
LQ Newbie
 
Registered: Nov 2007
Posts: 5

Rep: Reputation: 0
vector string


hi,

i have a doubt in vector strings what are these vector strings.
and if this is a vector how to find the dimention of these vector or what
is the dimention of this vector.

and how to do vector string things in c language.
 
Old 11-14-2007, 06:04 AM   #2
keratos
Member
 
Registered: May 2007
Location: London, UK.
Distribution: Major:FC8. Others:Debian;Zenwalk; Arch; Slack; RHEL.
Posts: 544

Rep: Reputation: 30
Dont really understand your English.

Taking a wild guess, are you interesting in 'C' programming constructs?

In particular, vector arrays?

http://www.cppreference.com/cppvector/index.html
 
Old 11-14-2007, 01:49 PM   #3
osor
HCL Maintainer
 
Registered: Jan 2006
Distribution: (H)LFS, Gentoo
Posts: 2,450

Rep: Reputation: 78
Linked to above is not a C but a C++ vector reference. There really is no C-language vector (there are “arrays” which are contiguous memory areas holding a series of objects of a single type). Up until recently (C99), an array’s length was always determined at compile-time. Now an array’s length may be variable. Still, arrays are much different from vectors (for example, you can’t “grow” or “shrink” arrays).

You can implement your own vector functions in C using the memory allocation functions such as malloc(), calloc(), and realloc(). They will probably not be as type-generic as the C++ template-based stl vectors though (unless you are really creative with your preprocessing).

Last edited by osor; 11-14-2007 at 01:50 PM.
 
Old 11-15-2007, 12:15 PM   #4
aaabhish
LQ Newbie
 
Registered: Nov 2007
Posts: 5

Original Poster
Rep: Reputation: 0
thanx osor,
but how will i implement vector function using memory functions melloc, calloc and realloc.
as there mast be some dimention of vectors so here in this case what will be the dimention
of vector after implementing it from malloc like functions.


and yes i m interested in c programming constructs.
 
Old 11-15-2007, 01:03 PM   #5
rsashok
Member
 
Registered: Nov 2006
Location: USA, CA
Distribution: RedHat, Debian
Posts: 202

Rep: Reputation: 31
How about thit as a template:

Code:
typedef struct
{
   uint32_t   size;
   uint8_t    *data;
} vector_t;

vector_t *create_vector(uint32_t size)
{
   vector_t   *new_vector = NULL;
   
   if ((new_vector = calloc(1, sizeof(vector_t)) != NULL)
   {
       if((new_vector->data = calloc(1, size)) != NULL)
           new_vector->size = size;
   }
   return(new_vector);
}

uint32_t add_vector(vector_t *first, verctor_t *second, vector_t *result)
{
    uint32_t   i, retv;

    if ((first->size == second->size) && (result->size <= first->size))
    {
        for(i = 0; i < first->size; i++)
           result->data[i] = first->data[i] + second->data[i];
        
        retv = !0;
    }
    else
    {
         retv = 0;
    }
   return retv;
}
Go ahead and add whatever you want, tailor to your own needs - only you know what you want.
 
Old 11-17-2007, 10:24 AM   #6
aaabhish
LQ Newbie
 
Registered: Nov 2007
Posts: 5

Original Poster
Rep: Reputation: 0
what are this uint32_t and uint_8.
 
Old 11-17-2007, 10:40 AM   #7
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
Typedefs for 32-bit and 8-bit unsigned integers, I'd imagine.
 
Old 11-17-2007, 11:16 AM   #8
rsashok
Member
 
Registered: Nov 2006
Location: USA, CA
Distribution: RedHat, Debian
Posts: 202

Rep: Reputation: 31
If you are working on 32-bit computer (and most likely you are then):
Code:
typedef unsigned long uint32_t
typedef unisgned char uint8_t
and so on for the rest of them signed and unsigned. It will make your code more portable, and what is even more important more readable.
 
Old 11-18-2007, 02:12 PM   #9
keratos
Member
 
Registered: May 2007
Location: London, UK.
Distribution: Major:FC8. Others:Debian;Zenwalk; Arch; Slack; RHEL.
Posts: 544

Rep: Reputation: 30
There are 'C' modules that can be added, to service vector types or quite simply, arrays of arrays (variable length) for that is what a vector is anyway!
 
  


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
LXer: Vector Linux 5.9-Pseudo64-0.1 -- Finally, 64-bit Vector LXer Syndicated Linux News 0 09-12-2007 01:20 PM
Convert C++ String Vector to char array anamericanjoe Programming 1 12-12-2006 09:29 PM
can i modify int 80 vector to a user-defined vector qqrilxk Linux - Security 1 03-03-2005 08:46 PM
adding to vector<string> in a struct niteshadw Programming 3 02-03-2005 07:08 PM
Miseries at install from HDD&floppies, with vector ISO& how to boot with vector linux prctom VectorLinux 9 06-29-2004 05:27 AM

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

All times are GMT -5. The time now is 08:47 AM.

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