Linked Questions
71 questions linked to/from How can I correctly assign a new string value?
2
votes
1
answer
16k
views
I am getting an error "warning: assignment to 'char' from 'char *' makes integer from pointer without a cast" [duplicate]
struct student {
char name[30];
char rollNumber[20];
char class[2];
};
void test(int length){
struct student* tempStudent = (struct student*)malloc((length+1)*sizeof(struct student));
...
1
vote
2
answers
3k
views
How to assign a string value to two dimensional array in C? [duplicate]
How to assign a string value to two dimensional array in C?
I have a sample code, but its not working.
#include<stdio.h>
void main()
{
char f[20][20];
f[0]="abc"; //Error Happens ...
0
votes
1
answer
4k
views
Insert char * into binary search tree in C [duplicate]
Hi i am trying to insert char *keyin = NULL and char *valuein = NULL; to my binary search tree, but error message appears like:
Yelp1.c:111:11: error: assignment to expression with array type
r->...
-2
votes
1
answer
1k
views
C initialization makes integer from pointer [duplicate]
#include <stdio.h>
void add_element(char object[20], int price);
struct linked_list {
char object[20];
int price;
struct shopping_list *next;
};
struct linked_list list = {"car", ...
0
votes
3
answers
2k
views
Set the value of a C string to a string literal [duplicate]
For some reason, I get a compiler error whenever I try to set the value of a C string to a string literal:
#include <stdio.h>
int main(void) {
char hi[] = "Now I'm initializing a string.";
...
-3
votes
3
answers
735
views
Why does malloc seemingly allow me to write over memory? [duplicate]
Why does this not return a segmentation fault 11?
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char const *argv[])
{
char *test;
test = (char*) (malloc(sizeof(char)*...
1
vote
2
answers
765
views
Reusing structs in loop (in C) [duplicate]
I'm trying to insert data into a Data struct first, then parse it to an insertFirst function that can put it into my linked list. This is all done in a while loop.
while(fgets(line, 8, file) != NULL)
...
-3
votes
2
answers
929
views
how to replace a macro with a string? [duplicate]
#include <stdio.h>
#include <stdarg.h>
#define ammo "full"
int main()
{
char a[100];
a = ammo;
printf("%s",a);
return 0;
}
I am trying to replace #define ammo with "full" (string) ...
0
votes
2
answers
1k
views
String matrix input output [duplicate]
I want to make a matrix of strings in C Programming language
this is my code
void main()
{
char Data[10][3][20];
int i=0;
int j=0;
for (i=0;i<10;i++)
{
for (j=0;j<...
1
vote
2
answers
226
views
Error in C - expression must be a modifiable lvalueC/C++(137) [duplicate]
I am trying to create a phonebook struct and to assign values to the elements of the array:
#include <stdio.h>
#include <string.h>
typedef struct
{
char name[30];
char number[30];
...
1
vote
1
answer
698
views
incompatible pointer to integer conversion assigning to char from char[13] [duplicate]
i have create a student structure and when i am assigning name to the character array defined inside the structure then it is giving me an error "incompatible pointer to integer conversion ...
0
votes
2
answers
623
views
Wrong values in Array containing Structs in C [duplicate]
I have this struct:
(struct.h)
#pragma once
#ifndef STRUCT_H
#define STRUCT_H
typedef struct {
unsigned int id;
char *name;
char *address;
} Struct;
#endif
I made a dynamic array ...
-1
votes
1
answer
334
views
Cannot output the C struct char array member [duplicate]
I'm learning how to use structures in C. But in the following code I couldn't print myArray "HELLO!" which is declared as a char array:
#include <stdio.h>
struct myStruct
{
int ...
-3
votes
5
answers
207
views
C alocate memory using malloc [duplicate]
I do not understand very well.
char *string;
string = malloc(1);
if (string == NULL) {
printf("Couldn't able to allocate requested memory\n")
} else {
string = "testing";
}...
2
votes
2
answers
81
views
Why does my C program segfault when I use strcat with dynamically allocated char arrays? [duplicate]
I need some help understanding the difference in behavior with strcat when passing in dynamically allocated char arrays versus char arrays declared with the index operator.
The following generates a ...