Mfw spent 5 hours trying to figure out why I can't get the first char of a char pointer in C whilst Rust Just Works

>mfw spent 5 hours trying to figure out why I can't get the first char of a char pointer in C whilst Rust Just Works

Attached: i648gmqsk74y.png (645x1260, 440K)

Attached: 1540945132977.jpg (208x326, 15K)

...dereference the pointer and you get the first char.

Go read your K&R bubs

#include

int main() {
char *string = "test";

printf("%s", *string);

return 0;
}

doesn't work.

>printf("%s", *string);

Attached: 1536335269763.jpg (550x339, 32K)

I can't find a sufficiently retarded brainlet wojak image for this post. This has to be bait.

meanwhile in Rust
fn main() {
let text = "test";
let ch = text.chars().nth(0).unwrap();

println!("{}", ch);
}

why is Rust so based??

Because *string isn't a string, but a single char, moron. Read about format strings (man printf.3) and use the proper one.

How is it a single char when I've assigned a string to it? And why does it appear as a string when I print it?

You're deferencing the pointer, which is a single char (promoted to int) to the start of the string. What shitty compiler are you using? GCC will warn you, which gives enough detail

Attached: Screenshot_2018-11-06_17-20-44.png (586x87, 13K)

gcc version 8.2.1

I don't get that warning though.

#include

int main ( int argc, char **argv )
{
char *test = "OP is a faggot.";

//also prints the string
puts( test );
//prints the string
printf( "%s\n", test );
//prints two characters
printf( "%c%c\n", *test, *( test + 1 ) );
//prints three characters
printf( "%c%c%c\n", test[ 8 ], test[ 9 ], test[ 10 ] );

return 0;
}

>#include
why do you have to include all of Adobe Studio to just print a string?

this
>lol no prelude

on second thought, stick to rust.

So it's a bait thread, then.

but how can he if his brain littererly has infinite power

You need

printf("%c", *string);

meanwhile in D
void main() {
import std.stdio : writeln;
import std.uni : byGrapheme;
import std.range : front;

writeln("খাইতে মজা মুড়ি, চুদতে মজা বুড়ি".front);
}
}

Ah, I see that byGrapheme is not necessary after all, sorry I was just phoneposting.

Its not the type problem here man

"no" dumbass

The problem here is deeper than you imagine.
You clearly don't understand how pointers work and why you should not use *string in the printf.
I suggest you go over chapter 10 - Pointers in the Kochan C book .

>mfw spent one day trying to figure out how to compile libcurl in C project on Windows with no success

Attached: 1538601686327.jpg (554x921, 70K)

Attached: grad.png (512x491, 93K)

That looks like vomit.

>mfw still wondering why the fuck does GMP has its own memory allocation functions.
Luckily I only had to use that crap once, and pure C for that matter.

Attached: heh.png (1920x1080, 2.17M)

Meanwhile in C.
#include

int main ( int argc, char **argv )
{
char *test = "test";
char ch=test[0];
printf( "%c", ch );

return 0;
}

>doesn't support unicode characters
Truly, meanwhile in C.

C and C++ suck for unicode, not gonna deny it.

Meanwhile in C#
using System;

public class Test
{
public static void Main()
{
Console.Write("খাইতে মজা মুড়ি, চুদতে মজা বুড়ি"[0]);
}
}

>খাইতে মজা মুড়ি, চুদতে মজা বুড়ি
Top kek. Didn't know there are /bd/ in board.

I just used the line from , I don't know that moonspeak.

Rust and D seems nice.

Why are rust programmers so stupid ?

But how do you do it though?

In GoD we tRust

EZPZ

Attached: 1539093341882.jpg (640x775, 106K)

American Standard Code for Information Interchange

... is deprecated

The C Programming Language, 2nd edition.
Go read it. Urgently.

#include

>named my char* "string"
>this creates a string datatype and also magically turns the char behind the pointer into said new datatype without casting
Do you have a CS degree so we can add this to the collection?

In C there are no unicode chars and there can not be one, char is strictly one byte. Just use string functions for all of them and don't trust strlen. For anything more advanced use some kind of library.

We already had this fucking thread

What's the best C unicode library? Not just basic string stuff, but unicode-specific algorithms like normalization.

>char is strictly one byte
That's why you use wchar_t and wide character functions.

>unironically using wchar_t
HAHAHAHAHAHAHA fuck you

That's not enough for full unicode, you know.

I am sorry, but how is this user wrong? Doing what he says gets the first character from "string". So I am confused on how he is wrong.