Yes I'm gonna fix that. Thank u again :)
Type: Posts; User: zel
Yes I'm gonna fix that. Thank u again :)
Ok, it was that simple and I've stuck here for so much time...:$
for (i=0;i<N && str2[i]!='\0';i++){
str1[i]=str2[i];
}
str1[i]= '\0';
I don't know why I think so...
Haha. I see that.
OK.
it runs properly except :
1) that if eg. len2=5 and I give 5 as N,it does no changes.
and
2)if eg. len2=5 and I give 10 ,it never goes out of the loop.
gr..I made it...
Oh sorry. I didn't see your answer. Is my code now correct?
So I did this:
void copy( char* str1,char* str2, int N) {
int i,len1,len2;
for (i=0; str1[i] != '\0'; i++){
len1= i;
}
ok here's another problem. I want to copy the first N characters from a string1 to a string2 and erase the rest characters of string1 BUT without using any string function from <string.h>.
So if...
Ok problem solved. Thank u again :)
ok I also added 2 free.
free(pX);
free(pY);
I'm confused at the 2nd part of your answer. you mean I don't have to use str1 and str2 but pX and pY instead?
ps.sorry if my English is bad
so it has to be:
[
pX = (char *) malloc(20* sizeof(char) );
pY = (char *) malloc(20* sizeof(char) );
/CODE]
right?
Ok. How about this one?
My warnings are:
In function ‘main’:
line 11: warning: assignment makes integer from pointer without a cast
line 12: warning: assignment makes integer from pointer...
oops..ok I found the mistake thx 2 u. nice :)
I am writing a programme..and it's so simple but I get this warning all the time.
warning format ‘ d’ expects type ‘int ’ but argument 2 has type ‘char *’
What could have gone wrong?