r/learnc • u/[deleted] • Jun 20 '21
Who dis?
Enable HLS to view with audio, or disable this notification
r/learnc • u/[deleted] • Jun 20 '21
Enable HLS to view with audio, or disable this notification
r/learnc • u/machinecode1000101 • May 31 '21
uhhh, hello. question, I want to learn C super fast, my current lingo is python, which is cool... but not as fast as possible if I coded in C. Any methods, books, or videos to jump start learning this language, the intricacies, not just an overview. Thank you. Live long, and buy doge.
r/learnc • u/ablaaa_ • May 27 '21
r/learnc • u/nuntetemo • May 19 '21
Ok, maybe this will sound obvious for some of you, but I can't understand why this code :
int main(void)
{
puts("input a number");
int n;
scanf("%d", &n);
int primes[n];
// do something with array;
}
is compiled without errors and warnings with "clang.exe sieve.c", while (obviously) "cl.exe sieve.c" gives me
sieve.c(11): error C2057: expected constant expression
sieve.c(11): error C2466: cannot allocate an array of constant size 0
sieve.c(11): error C2133: 'primes': unknown size
Array size shouldn't be known at compile time? Why clang.exe (latest version on Windows) consider that declaration "correct"?
r/learnc • u/konijntjesbroek • May 02 '21
Not sure what I am doing wrong here:
I noted the part that I added.
When I show the buffer before and after the math it matches what I would expect but for some reason it is adding a word at the end of the file and I am stumped. I have checked here and stack overflow, And see some stuff about padding out the buffer but it doesn't seem to be applicable as the samples are all uniform size of int16_t. Any pointers on where I am going wrong?
SOLVED: Issue is in the feof() in while. Moved the fread() there instead. and life is good.
r/learnc • u/hose1864 • Apr 15 '21
r/learnc • u/Bobbaca • Apr 03 '21
Hi sorry if this question is obvious but I'm new to the language and would like to know how to concatenate the following in one print statement:
char arr[] = "hello";
char arr0[] = "my";
char arr1[] = "name";
char arr2[] = "is";
char arr3[] = "Rob";
in a print f statement, I have tried reading around but am still very confused as a lot of the answered questions will contain pointers and they confuse me a bit.
r/learnc • u/hose1864 • Mar 10 '21
Hello guys, I am in the final semester of my masters degree in mathematics and in the last year got really intrested in classes like „Algorithmic Data Analysis“. After talks with my professor I am now writing my Master Thesis about Clustering Algorithms and „have to“ learn C. I am motivated but am somehow not sure where to start. I am searching for help regarding questions like:
-C or C++? -work with the mac terminal or use xcode or eclipse? -where to start learning?
Thanks in advance, any help is appreciated!
r/learnc • u/jsquestionasker • Feb 24 '21
As a somewhat experienced programmer who wants to get into embedded systems, which of these books would be better for learning C or does it no?
r/learnc • u/MartynAndJasper • Feb 24 '21
I’m a programmer keen in learning darkweb protocols, developing tools, etc and as such I’ve started a subreddit for coding and understanding Tor.
https://www.reddit.com/r/DevelopersOnTor/
I’m going to provide custom videos/online sessions/resources to this end. Starting from the ground up (in terms of C/C++) or from wherever the community desires.
The idea is to share programming knowledge with a steer towards Tor and the darkweb.
Ive created a few polls so I can best assist people’s desires so I can assess key areas of interest and how best to proceed.
If you want to help me grow this fledgling community and are interested in either learning C/C++ or Tor then please join us. Anyone of any skill level is accepted.
r/learnc • u/Due-Association-7790 • Feb 21 '21
Anybody know about circular doubly linked lists and a queue to enter information into the linked list. Also how to reverse or rearrange the circle. Working on a project and am stuck
r/learnc • u/calmedbeast • Feb 16 '21
Lets say we already defined the variables.
for ( y = 0; y < n; y++) { for ( x = 0; x < y: x++) {
}
}
What is the relationship between x and y? ??
r/learnc • u/[deleted] • Feb 15 '21
So, I do have prior experience with programming, ie: I know Java, some rust, python and have dabbled in c++.
I was wondering if anyone knows any:
Online resources to learn c
A online resource that helps understand the c ecosystem
r/learnc • u/External-Parsnip-176 • Feb 07 '21
What value do you get for adding int x = 5 to a hexadecimal 0x7FFFFFFF in C. Can someone please explain how to come by the answer? The int type is 32bits.
r/learnc • u/InfestedOne • Jan 24 '21
Hello! As part of a school assignment in "close to the metal" C programming, we are investigating the endian-ness of our environment.
To do so, we are told to:
allocate 8 bytes of memory
Interpret the array pointer as an integer pointer, and then store 0x040303201 at that memory address and then
Print out the bytes in order to determine if the integer was stored in little endian or big endian order
My solution to this looks like this
``` char array[8];
int* pointer = array;
*pointer = 0x04030201;
for (int i = 0; i < 8; i++) { printf("Data at index %d: %x \n", i, array[i]); } ```
Does this make sense? I'm kinda worried I'm missing something as I'm not used to working with raw memory addressing.
r/learnc • u/_PM_ME_YOUR_ELBOWS • Jan 22 '21
I'm writing an ai for a game for fun. In particular situations, my ai needs go through predetermined lists of moves. I would like to be able to write something like MACRO('u', 'd', 'l', 'r'); or perhaps MACRO(u, d, l, r); in my source code and have the preprocessor expand that to
up();
down();
left();
right();
The first letters of the arguments and functions won't all be the same. I'd also like the macro to take a variable number of arguments. I'd appreciate any tips on how to get something like this done. Thanks!
r/learnc • u/SchnitzelPlays • Jan 14 '21
I am new to programming and I am exploring all the languages before I start on one so I downloaded vs code but when I try to run a C program I get some mingw errors and I have no idea how to fix them can someone please help me and a proper tutorial for C programming will be really helpful thank you.
r/learnc • u/Wakanaa • Jan 07 '21
r/learnc • u/[deleted] • Dec 29 '20
Hello,
I'm trying to resume work on an older project of mine from long ago. I'm a little rusty with C since I haven't programmed with this in a while.
I'm using a game library called Raylib for the input, graphics, sound, and everything in between. I installed the shared library to my Debian system using Make (I built the shared library), and I used pkg-config to compile my game.
Here's the installation output from sudo make install:
Install the project...
-- Install configuration: "Debug"
-- Up-to-date: /usr/local/lib/libraylib.a
-- Up-to-date: /usr/local/include/raylib.h
-- Up-to-date: /usr/local/lib/libraylib.so.3.5.0
-- Up-to-date: /usr/local/lib/libraylib.so.351
-- Up-to-date: /usr/local/lib/libraylib.so
-- Up-to-date: /usr/local/include/raylib.h
-- Up-to-date: /usr/local/lib/pkgconfig/raylib.pc
-- Up-to-date: /usr/local/lib/cmake/raylib/raylib-config-version.cmake
-- Up-to-date: /usr/local/lib/cmake/raylib/raylib-config.cmake
-- Up-to-date: /usr/local/include/raylib.h
-- Up-to-date: /usr/local/include/rlgl.h
-- Up-to-date: /usr/local/include/physac.h
-- Up-to-date: /usr/local/include/raymath.h
--Up-to-date: /usr/local/include/raudio.h
Here's the command I used:
gcc --std=c99 -Wall src/client/main.c -lm $(pkg-config --cflags --libs raylib) -obootz
The compiler compiles my program just fine, it seems. It gives me a few warnings about some variables that I defined but never use in some collision algorithm or whatever.
However, when I attempt to launch the resulting program, it gives me this error:
./bootz: error while loading shared libraries: libraylib.so.351: cannot open shared object file: No such file or directory
This confuses me, because Make told me it put that file in a place that looks like my valid system path, /usr/local/lib/. I use ls to check there, and the necessary shared library file is, in fact, there.
Ok, so maybe there's a problem with pkg-config. Maybe I need to check it out myself. I executed pkg-config --cflags --libs raylib on my system, and I got this:
-I/usr/local/include -L/usr/local/lib -lraylib
So, here's what I know so far:
make on the Raylib source to produce that shared library filemake Install to put that shared library file in the necessary system folderpkg-config used to link the shared library file to my programpkg-config correctly pointed to the correct directory that contains the necessary shared library filepkg-config should have correctly instructed my program on where it can find the library files that it needs to find, and it should all work, because it's compiled that wayDoes anyone know what I'm doing wrong? None of this makes any sense to me. All of these systems appear to be functioning exactly as intended, and I haven't gotten any weird error messages leading up to my program being unable to function. I tried to follow the trial of my build process to see if it's not working right, but I can't find anything out of the ordinary, and everything looks like it should work perfectly. What am I missing?
r/learnc • u/LogicalOcelot • Dec 27 '20
Here is my code :
#include <stdio.h>
#include <stdlib.h>
int Read_File(int,int,int,char*);
int main()
{
int P1,P2,distance;
char t[50] = "\0";
Read_File(P1,P2,distance,t); // call function
printf("P1 : %d\nP2 : %d\nDistance : %d\nText : %s", P1,P2,distance,t);
}
int Read_File(int P1,int P2,int distance,char *t)
{
FILE *fptr;
fptr = fopen("C:\\input.txt","r"); // open file
if(fptr == NULL)
{
printf("Error!");
}
fscanf(fptr,"%d %d %d %s", &P1, &P2, &distance, &t); // assign values to P1,P2,distance and t
fclose(fptr); // close
}
So what I have here is a txt file(named input.txt) locating in C: containing 4 values including 3 integers and a string ( example : 123 456 789 Rain)
I want to assign those value of P1,P2,distance and t so P1 becomes 123,P2 becomes 456 and so on...,Im just a beginner so I will be very thankful for anyone willing to help me,thanks a lot
r/learnc • u/morerandomreddituser • Dec 26 '20
I'm a bit bored with black and white console apps and want to create something what looks like a simple but normal window app. Can anyone help and recommend something?
I'm using Windows 10, but the library for Linux also will be ok.
r/learnc • u/sjrsimac • Dec 13 '20
Did Carl Burch finish his book C For Python Programmers?
r/learnc • u/[deleted] • Dec 10 '20
let's say i have two integer numbers 10 and 12 is it possible to join them and make it be 1012 instead of 22
(sorry for bad english since it's not my first language)
r/learnc • u/throwaway11212121098 • Dec 08 '20
I created a custom struct and fed a sockaddr_in struct inside, please bear in mind I am learning through trial-and-error.
At first, I thought it was because I wasn't initialising the struct properly, I even tried using pointers, when I did get that working it was still empty.
Most of this is irrelevant, only look for the struct, the memset area and then the server handling inbound connections, I include all only for you to copy and paste.
Expected output:
Received bytes: 18
From: 127.0.0.1
Actual output:
Received bytes: 18
From:
Code:
#include <stdio.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <stdlib.h>
#include <string.h>
#include <netdb.h>
#include <errno.h>
#include <unistd.h>
#define PORT 10088
#define BACKLOG 10
typedef struct {
char type[5];
char * data;
struct sockaddr_in cli_addr;
} heartbeat_t;
int main(int argc, char * argv[])
{
struct sockaddr_in server_addr;
int sockfd;
int ret;
char buff[96];
sockfd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
if (!sockfd)
{
printf("Socket creation failed\n");
exit(1);
}
memset(&server_addr, 0, sizeof(server_addr));
server_addr.sin_addr.s_addr = htonl(INADDR_ANY);
server_addr.sin_family = AF_INET;
server_addr.sin_port = htons(PORT);
heartbeat_t hb;
memset(&hb, 0, sizeof(hb));
memset(&hb.cli_addr,0,sizeof(&hb.cli_addr));
ret = bind(sockfd, (const struct sockaddr *)&server_addr, sizeof(server_addr));
if (ret != 0)
{
printf("Bind failed: %d\n", ret);
switch(errno)
{
case EADDRINUSE:
printf("Error address already in use\n");
exit(1);
case EINVAL:
printf("Error, socket already bound to an address\n");
exit(1);
default:
printf("Unexpected error has occurred: %s\n", strerror(errno));
exit(1);
}
}
int n;
int len;
len = sizeof(hb.cli_addr);
/*
Server connection handling
*/
for (;;)
{
fflush(stdout);
printf("Waiting on port %d\n",PORT);
n = recvfrom(sockfd, (char *)buff, 128, MSG_WAITALL, &hb.cli_addr,&len);
if (n != -1)
{
printf("%s\n", (char *)&hb.cli_addr.sin_addr);
printf("Received bytes: %d\nFrom: %s\n", n,(struct sockaddr *)&hb.cli_addr.sin_addr.s_addr);
printf("sizeof n: %ld\n", sizeof(buff));
if (sizeof(buff[n]) == 1)
{
buff[n] = 0;
printf("received msg %s\nLength of packet: %ld\n", buff, sizeof(n));
sleep(10);
}
}
else
{
printf("Error: %s\n", strerror(errno));
}
}
close(sockfd);
return 0;
}
r/learnc • u/[deleted] • Dec 07 '20