C
Chad
Given the following...
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define MAX 100
void choparray(char **s)
{
int i;
int j;
char nrows;
char ncolumns;
ncolumns = 10;
nrows = 10;
char **buf = malloc(nrows * sizeof(char *));
for(i = 0; i < nrows; i++)
buf = malloc(ncolumns * sizeof(char));
j = strlen(*s) -1;
strcpy(*buf, *s);
*buf+j = '\0';
}
int main(void)
{
char *stuff[]= {"test", "this"};
choparray(stuff);
printf("after: %s\n", *stuff);
return 0;
}
I get "invalid lvalue in assignment" when I try to compile it....
$ gcc -g strip.c -o strip
strip.c: In function ‘choparray’:
strip.c:24: error: invalid lvalue in assignment
How come
*buf+j = '\0';
Wouldn't be equivalent to
buf[j] = '\0';
in this case
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define MAX 100
void choparray(char **s)
{
int i;
int j;
char nrows;
char ncolumns;
ncolumns = 10;
nrows = 10;
char **buf = malloc(nrows * sizeof(char *));
for(i = 0; i < nrows; i++)
buf = malloc(ncolumns * sizeof(char));
j = strlen(*s) -1;
strcpy(*buf, *s);
*buf+j = '\0';
}
int main(void)
{
char *stuff[]= {"test", "this"};
choparray(stuff);
printf("after: %s\n", *stuff);
return 0;
}
I get "invalid lvalue in assignment" when I try to compile it....
$ gcc -g strip.c -o strip
strip.c: In function ‘choparray’:
strip.c:24: error: invalid lvalue in assignment
How come
*buf+j = '\0';
Wouldn't be equivalent to
buf[j] = '\0';
in this case