Questions tagged [c]

C is a general-purpose programming language used for system programming (OS and embedded), libraries, games and cross-platform. This tag should be used with general questions concerning the C language, as defined in the ISO 9899 standard (the latest version, 9899:2018, unless otherwise specified — also tag version-specific requests with c89, c99, c11, etc). C is distinct from C++ and it should not be combined with the C++ tag absent a rational reason.

Filter by
Sorted by
Tagged with
-1
votes
1answer
50 views

How can I create a char array variable that changes its value every time I run the code?

I am using char array variable which is declared like this : char our_thread[8]="thread1"; I am using it into a function which creates threads : kthread_create(thread_fn,NULL,our_thread); The ...
-4
votes
1answer
76 views

loops doing too many iterations in C [on hold]

I have a function that converts numbers from hex to decimal in C. the problem im having is that im seeing unexpected problem in my loops. im really new to programming in C. My program looks something ...
-1
votes
1answer
54 views

Making a menu inside a menu

I am trying to make a menu within a menu. My problem is that the value of "choice" is not changed and thus the program stops when I am trying to change the value of choice, e.g. when I entered (2) as ...
-1
votes
0answers
32 views

SPOJ : https://www.spoj.com/problems/SDITSBST/ Solution not getting accepted

Problem : https://www.spoj.com/problems/SDITSBST/ In this problem you are given two type of query Insert an integer to the list. Given an integer x, you're about to find an integer k which ...
1
vote
1answer
26 views

Why is my program not calculating Mean Response Time accurately for a Round Robin (Quantum = 4) Scheduling Simulation Program in C?

for my assignment, we were given a program that would simulate a FCFS scheduling algorithm in C, and we were to modify it twice to simulate SJF and RR (Quantum 4) and compare the mean response times ...
5
votes
3answers
77 views

Why does freeing the memory lead to segmentation fault?

I´m desperate because this code form time to time gives me a segmentation fault and I have no clue why. Actually it´s only supposed to add some linked list notes, print them and then empty the list by ...
0
votes
0answers
13 views

Compile application without linking libssl.a and libcrypto.a

Makefile: OPENSSLDIR = /usr/local/ssl/fips­2.0 OPENSSL_INCLUDEDIR = /root/poc/openssl-1.0.2r/include/ FIPSMODULE = $(OPENSSLDIR)/lib/fipscanister.o CC = /usr/bin/gcc FIPSLD_CC = $(CC) FIPSLD = /usr/...
-1
votes
2answers
58 views

Scanning Values Until Getting a Significant Character in C

For my homework, I am trying to code a calculator which can also calculate average of taken numbers. I don't want to ask for number of numbers because our teacher don't want it in that way. So I ...
0
votes
0answers
17 views

Temboo Stuck waiting

I am trying to use Temboo to read messages from an SQS queue, but no matter what Temboo sketch I use, the serial monitor ends up printing "waiting" forever. My Arduino Yun Rev 2 is connected to the ...
0
votes
0answers
21 views

Use of “@import” when C++ modules are disabled @import FBSDKCoreKit error

I exported a project from Unity, which included the Facebook SDK. Build gives an "Use of "@import" when C++ modules are disabled error in the files of Facebook SDK. I have: Xcode v11.1; Unity ...
-1
votes
0answers
19 views

udp broadcast cannot be received by another host

Using udp send broadcast message, the localhost server can receive, but on another PC in the same local network cannot receive. I check the broadcast mask are both 255.255.255.0. Code is following. ...
0
votes
1answer
29 views

build cannot find Platform Toolset = 'v141' in VS 2013

error MSB8020: The build tools for v141 (Platform Toolset = 'v141') cannot be found. To build using the v141 build tools, please install v141
-1
votes
1answer
27 views

Unable to pass extra parameter to existing function in Kamailio

Currently I am using Kamailio server for SIP communications. I am using ims_charging module. So from the script we are calling RO_CCR(6 param) function. Until this point it is working fine but the ...
0
votes
2answers
82 views

What is wrong? Runtime Error when running C code

I cannot find out why am I having a RunTime Error when I compile this code. Can someone tell me what is broken in my code? #include <stdio.h> int main(void) { int ai[100], n=0, m=0, test=0, ...
0
votes
0answers
19 views

How to Insensible input when user enter character in c program? [duplicate]

I wants to write a program in c language using bubble sort, i have written my program, it's working but what i want is insensible when i enter characters, i got solution but it exits when i enter ...
0
votes
3answers
59 views

how can i read data from a file then edit it and print it in the same file?

What I'm trying to do is read this text from a file: Tomorrow, and tomorrow, and tomorrow, Creeps in this petty pace from day to day, To the last syllable of recorded time; And all our ...
0
votes
1answer
60 views

how to make this faster?

I have a body of code that I need to be faster, any tips or solutions would be useful. Looking to have a higher amount of cache hits by re-ordering memory accesses to be as sequential as possible. ...
0
votes
0answers
15 views

SDL_ttf Accurate Glyph Metrics for Fonts when using outlines

I am using a c# wrapper for sdl (But this should not matter for this question, as I have accurate results for non-outlined fonts). I am making a texture containing every char for performance reasons ...
0
votes
1answer
25 views

Valgrind reports “still reachable” bytes when using vfwprintf

I am writing two functions as handy shortcuts for printing to stderr: one I am calling eprintf for printing regular strings; and ewprintf for printing wide-character strings. I have written eprintf as ...
0
votes
3answers
50 views

Validating Input goes into infinite loop

I am trying to validate the input if it is something else other than 1 to 3 it will prompt invalid input and also try to get a new input until it is valid. This piece of code is working well when I'm ...
0
votes
1answer
33 views

C all the value changes with the pointer

I am trying to write a method in C to read from a file. I don't know how long the file will be but I know the structure. The problem is that when I change the value of str, all my vars that refer to ...
0
votes
0answers
17 views

How can I use g_idle_add() to get window size?

I am trying to get window size after application the window is drawn and full screen I dont want a default 200x200 size. This article suggests using g_idle_add(). gpointer data; int width, height; ...
-1
votes
2answers
34 views

%s not working properly with my return value, in C

As the title says %s is not working properly This is for a code wars so %s needs to be able to work with the array to pass the sample test cases; Cannot change function declaration of playPass. Using ...
1
vote
1answer
67 views

Blurring an image with C

I am trying to blur an image based on the tutorial I am following. Here's the instruction. Blur There are a number of ways to create the effect of blurring or softening an image. For this problem,...
3
votes
4answers
70 views

How to find the length of every word in a string?

I wrote a code that takes a sentence and outputs every each word in a line. But I also want to write the size of each word next to it. Input: Hi my name is Current output: Hi my name is Desired ...
0
votes
0answers
35 views

ioctl bug returning -1 EINVAL in SPI transfer function

Not sure if this is C related or something to do with the linux kernel. I'm using an SPI library for Beaglebone called BlackLib, and it has an SPI transfer function. For some reason it wouldn't work ...
0
votes
1answer
25 views

Trying to create a 2d array by inserting characters retrieved from file stream

This is my code: #include<stdio.h> #define ROW 10 #define COLUMN 20 int main(int argc, char *argv[]){ FILE* fptr; char grid[ROW][COLUMN]; int i ,j; fptr = fopen(argv[1],"r"); for ( i =...
1
vote
2answers
38 views

How can I define an array of scanner input in C not in main()?

#include <stdio.h> #include <string.h> #define line 4 int array[line]; //This works perfect int s = user input; //assume the user typed in a value and I stored the value in s; ...
-1
votes
1answer
35 views

Sending and Receiving messages with Sockets in C?

I am working on a school assignment that deals with Sockets, where I have a client and a server. I am having trouble on my client side where I am not receiving what I want the server to send. Now, I'm ...
0
votes
1answer
41 views

Simply percent passing program not functioning correctly

My professor has asked us to build a simple program that takes in grades and shows the percent of the input grades that are passing. #include <stdio.h> #include <stdlib.h> int main() { ...
0
votes
0answers
20 views

Reading keyboard input in kernel thread polling

I wrote a simple kernel module to read a single character from the keyboard and it worked. #include <linux/kernel.h> #include <linux/module.h> #include <linux/ioport.h> #include <...
1
vote
0answers
46 views

Can clock() become slower inside a while loop?

I'm implementing a request-reply function on the BeagleBone Black for the UART. The function has to have a timeout measured in milliseconds. In order to measure the elapsed time I used the clock() ...
-1
votes
0answers
17 views

How to write an algorithm to free memory for all nodes in linked list and list itself? [duplicate]

These are the structs that I can use, but I can`t change anything in these structs I can`t even change function parameter or add new functions, I should free the linked list *list in this function ...
1
vote
2answers
52 views

problem with using scanf_s to get a string value

I try to use scanf_s to get the input from the user for the date and the month (the compiler with visual studio always asks you to use scanf_s and that is why i use it). It allows me to put in an ...
0
votes
0answers
21 views

undefined reference to `curl_easy_init' in Linux(ubuntu) - using cmake [duplicate]

I'm trying to compile a C code in Linux(ubuntu) using curl lib with the Cmake file but I'm getting an undefined reference to `curl_easy_init' and others. the console shows the message like below. ...
0
votes
2answers
26 views

C Serial Communication. WriteFile succeeds but my device only processes 1st character

I'm trying to implement serial communication with a hardware device that plugs into the USB port on my PC. Im writing the communication code in C using Visual Studio 2015. I'm using a USB sniffer to ...
0
votes
2answers
41 views

C Code Compiles with No Errors but Doesn't Run Right (command line arguments and pointers)

#include <stdio.h> int strcompare (char*); int main (int argc, char *argv[]) { int argIndex; for(argIndex = 1; argIndex <= argc; argIndex++) { strcompare(argv[argIndex]); printf("...
3
votes
1answer
44 views

Passing Multidimensional Arrays into a Function

I need to be able to pass a 2D array into the scanning function after scanning for the size of the array. Everywhere I've looked has told me that you can't pass 2D arrays without dimensions into a ...
5
votes
2answers
56 views

When returning the difference between pointers of char strings, how important is the order of casting and dereferencing?

For educational purposes (yes 42 yes) I'm rewriting strncmp and a classmate just came up to me asking why I was casting my returnvalues in such a way. My suggestion was to typecast first and ...
2
votes
2answers
64 views

Math is not outputting correctly

I am still learning to code and wrote this code to get the total after the weight and distance are calculated. Can someone tell my why the math is not working? Example: When I enter 5 for weight and ...
0
votes
0answers
42 views

Trying to create multiples small multi-dimensional arrays with malloc

I'm trying to allocate two multi-dimensional arrays from a struct with a function. Allocating the first works perfectly but the second fails, even though the code for the two arrays is exactly the ...
-5
votes
4answers
68 views

How can I correctly format these loops in C how my professor wants it?

For my lab project I have to For each integer 0 < n <= 100, find all of the integers between one and n which divide n without a remainder. I have worked out the code but I am unsure how to ...
0
votes
0answers
36 views

How can I sort binary file entries without using an array in C?

I am writing a program for a university project in Linux. The program lets a user write name entries to a blank file.There is another binary file that has integers that show how many characters have ...
-3
votes
0answers
25 views

Trying to make a tiles game (“comparer wont read as intented after action”) [on hold]

Help pls i want to see if chain 1,2 and 3 are the same, but when i move a "tile" i cant compare my strings anymore p.s. i wrote a small backstory of whay it is im trying to do XD heres a smaller ...
0
votes
2answers
28 views

Structure in a Structure and Array

I have a few problems with the following assignments: a) Define a new data type tpos for storing the position of a solid in the two dimensional plane in single precision. Afterwards define another ...
0
votes
0answers
30 views

NASM x86 core dump writing on memory [duplicate]

I am learning assembly NASM and trying to do a LFSR code and call it on a C program to evaluate the execution time diference, but failed to figure out the problem with my code. My LFSR C version ...
-1
votes
0answers
33 views

scanf long long int int c codeblocks [on hold]

I'm using code blocks with c99. I tired getting a long long int input using: long long int num; scanf("%lld", &num); No matter what I tired it is not working. ps. long int and scanf("%ld", &...
0
votes
0answers
19 views

libgnuutils memory leak when threading

I'm doing some threading and I've been getting this memory leak. The threads run through then join at the end. I'm new to threading so I don't really know what the library error is shown by Valgrind ...
-5
votes
1answer
64 views

Get hidden characters of line feed in C

I have a work to do which I need to make a linux2dos function. Basically I have to find all line feeds (0X0A) and put carriage return before it (0X0D). As LFs and CRs are hidden in the file I don't ...
0
votes
0answers
26 views

How to insure 'scanf' got int and not double [duplicate]

I'm new in c and I want to scanf an int. To do it I use scanf("%d", number). Here is my problem: i want to make sure I got an int and not a double. For example, if got 1.0 , I want to print "got a ...