question about arrays in C, probably just a stupid "it's 1 am I can't think"

stonecold3169

Platinum Member
Jan 30, 2001
2,060
0
76
Hey all, I'm having a problem with a C program because I'm stuck on c++ and it's late and I'm not thinking right...

What I have is a simple fixed size array of Strings that I want to be able to delete something from the middle of it without changing the index, and just put white space in the deleted position. Hows abouts would I go about doing this? I realize this is the dumbest computer science question ever asked, but I can't think tonight and I have a loooong C hashtable lab due tommorow night that I wanted to get finished today and it seems the little things are what are frustrating me...

Can anyone help?
 

dighn

Lifer
Aug 12, 2001
22,820
4
81
use an array of char*'s. allocate memory for the ptr you want o insert string at and when deleting, free that ptr and set it to NULL

edit:

oops did u mean each string length is fixed? in that case umm do this: array[location][0] = '/0';
 

ufs

Senior member
Jun 3, 2001
310
0
0
myString[x]="";

hope it works... havent written a single line of code for a long time. economy sucks
 

Ameesh

Lifer
Apr 3, 2001
23,686
1
0
if you are using char * foo[] then just say

delete foo[index of string you want to kill] // do this step if you already allocated memory dynamically for the string in there
foo[index of string you want to kill] = NULL
 

ufs

Senior member
Jun 3, 2001
310
0
0
yeah... whatever... would have figured it out if i had a compiler handy
 

UCDznutz

Banned
May 11, 2002
1,278
0
0
Originally posted by: Ameesh
if you are using char * foo[] then just say

delete foo[index of string you want to kill] // do this step if you already allocated memory dynamically for the string in there
foo[index of string you want to kill] = NULL

hey i'm just wondering, what's with the 'foo' thing in programming? my professors have used it for functions, variable names, classes, etc.
 

dighn

Lifer
Aug 12, 2001
22,820
4
81
Originally posted by: Ameesh
if you are using char * foo[] then just say

delete foo[index of string you want to kill] // do this step if you already allocated memory dynamically for the string in there
foo[index of string you want to kill] = NULL

it would be free() in C

but i think he's using something like a char[a]

edit: there is a bracket-B-bracket after char[a] but it will not show up :(
 

Ameesh

Lifer
Apr 3, 2001
23,686
1
0
Originally posted by: dighn
Originally posted by: Ameesh
if you are using char * foo[] then just say

delete foo[index of string you want to kill] // do this step if you already allocated memory dynamically for the string in there
foo[index of string you want to kill] = NULL

it would be free() in C

but i think he's using something like a char[a]


that would just be a string not an array of strings and youre right he allocated with malloc he should use free, if he allocated with new he should use delete
 

dighn

Lifer
Aug 12, 2001
22,820
4
81
Originally posted by: Ameesh
Originally posted by: dighn
Originally posted by: Ameesh
if you are using char * foo[] then just say

delete foo[index of string you want to kill] // do this step if you already allocated memory dynamically for the string in there
foo[index of string you want to kill] = NULL

it would be free() in C

but i think he's using something like a char[a]


that would just be a string not an array of strings and youre right he allocated with malloc he should use free, if he allocated with new he should use delete


that is an array of arrays which = an array of strings

and there's no new/delete in C ;)

edit: whats with the bold. i didn't use it :confused:

oops i just looked at my post

it is messed up, if you use "quote" you'll see i typed char[a] but instead it shows up as char[a]

buggy forum :(

omg wtf is this. the refuses to show up. there is a after char[a]

WTF?!?!? bracket-B-bracket will not show up

i give up. anyway its char index a index B
 

manly

Lifer
Jan 25, 2000
13,067
3,825
136
Originally posted by: charrison
Originally posted by: ufs
myString[x]="";

hope it works... havent written a single line of code for a long time. economy sucks

wrong.

try mystring[x]=0; //null
NULL is not guaranteed to be 0 in C either, even though that's usually the case.
 

Ameesh

Lifer
Apr 3, 2001
23,686
1
0
Originally posted by: manly
Originally posted by: charrison
Originally posted by: ufs
myString[x]="";

hope it works... havent written a single line of code for a long time. economy sucks

wrong.

try mystring[x]=0; //null
NULL is not guaranteed to be 0 in C either, even though that's usually the case.


are you sure i thought NULL was #define to 0

 

Ameesh

Lifer
Apr 3, 2001
23,686
1
0
Originally posted by: dighn
Originally posted by: Ameesh
Originally posted by: dighn
Originally posted by: Ameesh
if you are using char * foo[] then just say

delete foo[index of string you want to kill] // do this step if you already allocated memory dynamically for the string in there
foo[index of string you want to kill] = NULL

it would be free() in C

but i think he's using something like a char[a]


that would just be a string not an array of strings and youre right he allocated with malloc he should use free, if he allocated with new he should use delete


that is an array of arrays which = an array of strings

and there's no new/delete in C ;)

edit: whats with the bold. i didn't use it :confused:

oops i just looked at my post

it is messed up, if you use "quote" you'll see i typed char[a] but instead it shows up as char[a]

buggy forum :(

omg wtf is this. the refuses to show up. there is a after char[a]

WTF?!?!? bracket-B-bracket will not show up

i give up. anyway its char index a index B



dude, i have no idea what you are talking about but if you want an array of strings you can do:

char **
char * []
char[][]
 

dighn

Lifer
Aug 12, 2001
22,820
4
81
Originally posted by: Ameesh
Originally posted by: dighn
Originally posted by: Ameesh
Originally posted by: dighn
Originally posted by: Ameesh
if you are using char * foo[] then just say

delete foo[index of string you want to kill] // do this step if you already allocated memory dynamically for the string in there
foo[index of string you want to kill] = NULL

it would be free() in C

but i think he's using something like a char[a]


that would just be a string not an array of strings and youre right he allocated with malloc he should use free, if he allocated with new he should use delete


that is an array of arrays which = an array of strings

and there's no new/delete in C ;)

edit: whats with the bold. i didn't use it :confused:

oops i just looked at my post

it is messed up, if you use "quote" you'll see i typed char[a] but instead it shows up as char[a]

buggy forum :(

omg wtf is this. the refuses to show up. there is a after char[a]

WTF?!?!? bracket-B-bracket will not show up

i give up. anyway its char index a index B



dude, i have no idea what you are talking about but if you want an array of strings you can do:

char **
char * []
char[][]


try editing your post and add char [ a ] [ B ] no space and u'll see the [ B ] (no space) refuses to show up
 

schizoid

Banned
May 27, 2000
2,207
1
0
Originally posted by: Ameesh
Originally posted by: schizoid
I went to ask my boss about arrays and he fired me.

hahaha what did he say? "you're fired n00b!"

No, he said "Hi, my name is Ameesh and I'm too stupid to get a bad pun."

You just got owned, loser.
 

cchen

Diamond Member
Oct 12, 1999
6,062
0
76
try editing your post and add char [ a ] [ B ] no space and u'll see the [ B ] (no space) refuses to show up

obviously because using a b inside brackets will make your text BOLD!
 

dighn

Lifer
Aug 12, 2001
22,820
4
81
Originally posted by: cchen
Originally posted by: dighn
Originally posted by: Ameesh
Originally posted by: dighn
Originally posted by: Ameesh
Originally posted by: dighn
Originally posted by: Ameesh
if you are using char * foo[] then just say

delete foo[index of string you want to kill] // do this step if you already allocated memory dynamically for the string in there
foo[index of string you want to kill] = NULL

it would be free() in C

but i think he's using something like a char[a]


that would just be a string not an array of strings and youre right he allocated with malloc he should use free, if he allocated with new he should use delete


that is an array of arrays which = an array of strings

and there's no new/delete in C ;)

edit: whats with the bold. i didn't use it :confused:

oops i just looked at my post

it is messed up, if you use "quote" you'll see i typed char[a] but instead it shows up as char[a]

buggy forum :(

omg wtf is this. the refuses to show up. there is a after char[a]

WTF?!?!? bracket-B-bracket will not show up

i give up. anyway its char index a index B



dude, i have no idea what you are talking about but if you want an array of strings you can do:

char **
char * []
char[][]


try editing your post and add char [ a ] [ B ] no space and u'll see the [ B ] (no space) refuses to show up


obviously because using a b inside brackets will make your text BOLD!


geez... i cant believe it. damned forum code
 

manly

Lifer
Jan 25, 2000
13,067
3,825
136
Originally posted by: Ameesh

are you sure i thought NULL was #define to 0
That may be by convention. But the symbol NULL refers to the null pointer on that architecture. There are rare systems where a different pointer address than 0 is the null pointer.

Argh, K&R C seems to clearly say NULL and 0 are equivalent. So what I'm speaking about doesn't refer to C source code, but to generated object code in particular implementations. My bad.
 

schizoid

Banned
May 27, 2000
2,207
1
0
Originally posted by: dighn
Originally posted by: schizoid
Originally posted by: dighn
where is the pun?

Wow.

You too?

english is not my first language

Well, then you might qualify for a pass on this one.

There is a pun...trust me.

(and it's a good one, if I do say so myself).

Esperanto is my first language.