Writing a C program but can\'t correctly get this function to work properly. her
ID: 3667132 • Letter: W
Question
Writing a C program but can't correctly get this function to work properly. here is a discription of the function;
kstring kstrfrom(const char *cstr)
Creates and returns a new kstring object that contains a copy of the contents of a null-terminated C string, including the null terminator.
The .length member of the returned kstring should be the length of cstr, plus one for the null terminator. The .data member should be a pointer to newly-allocated memory, into which you have copied the contents of cstr, including the null byte at the end.
If there is an error allocating memory, this function should call abort() or throw an uncaught exception.
Explanation / Answer
#include <stdio.h>
#include <string.h>
typedef struct kstring{
char ch[100];
} kstring;
kstring kstrfrom(const char *cstr){
kstring str;
strcpy(str.ch,(char*)cstr);
return str;
}
int main(){
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.