python (12.9k questions)
javascript (9.2k questions)
reactjs (4.7k questions)
java (4.2k questions)
java (4.2k questions)
c# (3.5k questions)
c# (3.5k questions)
html (3.3k questions)
How to print a specific character from a string in C
I'm recently practicing looping. I learned how to print: for example home to h ho hom home. by using
#include <stdio.h>
#include <string.h>
int main (){
char s[100];
printf(&...
atuy
Votes: 0
Answers: 3
strcpy() corrupts both strings if first argument is a char pointer
Define the following variables:
char *name1 = "Allan";
char name2[] = "Marco";
printf("%s %s\n", name1, name2); // Allan Marco
Then the following code works fine:
strcpy...
Ivan
Votes: 0
Answers: 2
Getting no output why is that?
I', learning C and I'm getting no output for some reason, probably I don't return as I should but how I should? (described the problem in the comments below :D)
Any help is appreciated!
#include <...
Patton13
Votes: 0
Answers: 2
ANSI C - Why malloc and free dont work for char pointers?
When I try to run this code:
char *s;
s = (char *) malloc (15);
s = "hello world";
free(s);
using gcc ts.c -ansi -Wall the result is:
free(): invalid pointer
Aborted (core dumped)
and the ...
alon ohana
Votes: 0
Answers: 1