Either allocate the string on the stack on the caller side and pass it to your function:
void getStr(char *wordd, int length) { ... } int main(void) { char wordd[10 + 1]; getStr(wordd, sizeof(wordd) - 1); ... }
Or make the string static in getStr
:
char *getStr(void) { static char wordd[10 + 1]; ... return wordd; }
Or allocate the string on the heap:
char *getStr(int length) { char *wordd = malloc(length + 1); ... return wordd; }
Related Posts:
- Return char[]/string from a function [duplicate]
- Return char[]/string from a function
- How does strtok() split the string into tokens in C?
- How to convert an int to string in C?
- What is a string of hexadecimal digits?
- How to convert an int to string in C?
- How to convert a string to integer in C?
- How do I create an array of strings in C?
- What is the difference between char s[] and char *s?
- How do I properly compare strings in C?
- How to convert an int to string in C?
- How do I create an array of strings in C?
- How to check if a string is a number?
- How do I lowercase a string in C?
- How to clear all the elements of array in C?
- How do I concatenate const/literal strings in C?
- Reversing a string in C
- How to remove the character at a given index from a string in C?
- Split string with delimiters in C
- Warning: return from incompatible pointer type in C
- Allocating string with malloc
- Removing trailing newline character from fgets() input
- Does C have a string type?
- error: function returns address of local variable
- How to concatenate string and int in C?
- The difference between char * and char[] [duplicate]
- Implementing Taylor Series for sine and cosine in C
- warning: implicit declaration of function
- pthread_join() and pthread_exit()
- Why should we typedef a struct so often in C?
- What is the difference between ++i and i++?
- Stack smashing detected
- Why am I getting “void value not ignored as it ought to be”?
- Pointer Arithmetic
- Openssl : error “self signed certificate in certificate chain”
- How do function pointers in C work?
- Expression must be a modifiable L-value
- “Expected expression before ‘ { ‘ token”
- How to generate a random int in C?
- How do I use valgrind to find memory leaks?
- C pointers and arrays: [Warning] assignment makes pointer from integer without a cast
- How to print the array?
- How to solve the error: assignment to expression with array type
- segmentation fault : 11
- What does “1e” mean?
- “error: assignment to expression with array type error” when I assign a struct field (C)
- how to use uint64_t in C [duplicate]
- How do I solve the following errors: “Undefined reference to WinMain”, “[Error] Id returned 1 exit status”?
- Warning comparison between pointer and integer
- What is use of c_str function In c++
- Connect: Socket operation on non-socket
- How to correctly use the extern keyword in C
- How do we check if a pointer is NULL pointer?
- how to use wait in C
- How do I calculate MB/s & MiB/s?
- How to create my own header file in c++?
- In C programming, what is `undefined reference`error, when compiling?
- double free or corruption (fasttop)
- Char Comparison in C
- C – The %x format specifier
- what is the unsigned datatype?
- lvalue required as left operand of assignment
- how to convert negative hexadecimal to decimal
- Why am I getting “undefined reference to sqrt” error even though I inclu de math.h header?
- Reading a string with scanf
- How to initialize a struct in accordance with C programming language standards
- Expression preceding parentheses?
- Linux equivalent of I_PUSH
- Understanding INADDR_ANY for socket programming
- getopt_long() — proper way to use it?
- C read file line by line
- The Definitive C Book Guide and List[
- When is it a good idea to use strdup (vs malloc / strcpy)
- C read file line by line
- Copying a part of a string (substring) in C
- Incompatible implicit declaration of built-in function ‘malloc’
- Need more information about Aborted (core dumped)
- How to solve error: expected identifier or ‘(‘
- When a number is written as 0x00… what does the x mean
- waitpid, wnohang, wuntraced. How do I use these
- How to pause in C?
- (.text+0x20): undefined reference to `main’ and undefined reference to function
- Why am I getting this error: “data definition has no type or storage class”?
- I’m getting “Invalid Initializer”, what am I doing wrong?
- Writing binary number system in C code
- Convert char array to string use C
- warning: passing argument ’from incompatible pointer type [enabled by default]’
- Return a `struct` from a function in C
- Scanning Multiple inputs from one line using scanf
- How do you allow spaces to be entered using scanf?
- Allocating char array using malloc
- Implementation of strtok() function
- switch case: error: case label does not reduce to an integer constant
- warning: incompatible implicit declaration of built-in function ‘printf’ [enabled by default]
- warning: return makes pointer from integer without a cast but returns integer as desired
- How to clear input buffer in C?
- Convert long long to string in C?
- Usage of \b and \r in C
- Parsing command-line arguments in C
- Compiler warning – suggest parentheses around assignment used as truth value