Anonymous
:D
Oleksandr
/warn for abuse of authority
🌚You just said that the Hindu is an insult
Oleksandr
😂
MᏫᎻᎯᎷᎷᎬᎠ
Oleksandr
e, bad english, sorry))
MᏫᎻᎯᎷᎷᎬᎠ
No problem
lock
Hey, to practise I also implemented the function to add content to array: void removeSpaces(char *str, int size) { int i = 0; int n = size; char str2[size]; while(i < n) { if(*str != ' ') { str2[i] = *str; i++; } str++; } printf("\n[OUT] %s", str2); }
lock
Working too
lock
[*] Removing spaces of string: ev efwef fewf [OUT] evefweffewf
Chetna
I did. They are very good points. Thank you for having me in this group.
Daniele°
lock
No
Yes, it is
lock
I tested a few minutes ago
Daniele°
Yes, it is
Miss null char terminator
lock
You need to specify char array addr and char array filesize and should work
lock
I forgot to post the updated one here
Daniele°
Yes
Try "Hello world "
Daniele°
void nospace(char const* str){ for(;*str; ++str) if(*str!=' ') putchar(*str); }
lock
But I can I add the null terminator to the string?
lock
Like
lock
strcat(str2, "\0");
lock
After the while loop
Daniele°
lol
Daniele°
strcat(str2, "\0");
You Need null char in str2 to use strcat
lock
Mmmm
Oleksandr
i think you need to start from another tasks
lock
I can say in the loop
lock
while(i < (n - 1))
lock
So null terminator is skipped
lock
Right?
Oleksandr
Oleksandr
that's all that u need
lock
while(i < (n - 1))
And could that work as other way?
Oleksandr
nope
lock
and where can I find more info about these stuff
Daniele°
#define MANY(T,N) (T*)malloc(sizeof(T)*(N)) char* nospace(char const* str){ size_t len = strlen(str); char* ret = MANY(char, len); char* dest = ret; for(;*str;++str){ if( *str!=' ') *dest++=*str; } *dest=0; return ret; }
Oleksandr
while just iterate throw str[], so if u change condition, it just increase or reduce count of iterations, that's all and ur problem is in str2[] array
lock
Thanks!
Daniele°
void ripspace(char* str){ char* dest = str; for(;*str;++str){ if( *str!=' ') *dest++=*str; } *dest=0; }
Daniele°
Segfault
Core dump
Oleksandr
why?
Daniele°
why?
Boh
Vladimir
Or not. I'm not sure
Daniele°
😂
Daniele°
Or not. I'm not sure
Yes, if not have a space
Daniele°
No
Oleksandr
there where no segfault
Vladimir
Segfault if str == NULL
Daniele°
Oleksandr
or i need to sleep a little bit
Daniele°
Segfault if str == NULL
the caller is responsible
Vladimir
the caller is responsible
No, you're responsible to check
Oleksandr
this depends on what are u really write
Daniele°
void ripspace(char* str){ assert(str); char* dest = str; for(;*str;++str){ if( *str!=' ') *dest++=*str; } *dest=0; }
Vladimir
No
Assume it's a library, and it's doc says you need to check all NULL's if you don't want sudden segfaults
Oleksandr
if (!str) return;
Daniele°
if (!str) return;
No, the caller is responsable
Vladimir
Where is a problems?
You would encounter problems if you try to write something with that kind of lib :)
Daniele°
At most, the called will make assert
Vladimir
stdlib from C doesn't check anything
It's... not very modern you know.
Oleksandr
as i said early, that depends on whar are you really want
Badugar
if (!str) return;
What does that return ? NULL, 0 or something else ?
Oleksandr
it may be fast unsafe library
Vladimir
I prefer to write safe code with no potentional segfaults
Oleksandr
or fully safe turtle
Vladimir
I recommend also check all mallocs for turning NULL
Daniele°
I recommend also check all mallocs for turning NULL
In Linux not return null by default