All Questions

Tagged with
Filter by
Sorted by
Tagged with
-5
votes
0answers
28 views

Substring of size is called good if the count of all 1s in this substring is not greater than m [on hold]

I am new to coding and I can't code this question as I can't understand how to detect the good substring in the binary string. It would be really nice if anyone can explain me with code, how it works ...
0
votes
1answer
47 views

I am getting an error message when trying to split a string and put them into an array

I am trying to split the user's input and put each delimiter in an array. For some reasons, with the code I have here, I get an error message: called object type 'char *[10]' is not a function or ...
-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 ...
1
vote
1answer
38 views

Programatically populate a uint8_t array

I have a uint8_t array which should look like this . uint8_t code[1000] = {0x66, 0xba, 0xf8, 0x03} Now I cant hard code values in that array instead , I need to insert them one by one from char ...
0
votes
1answer
29 views

Ringbuffer with sprintf

I'm trying to create a ringbuffer and fill it with an array of split string elements. Buffer Code is taken from here and works well enough. Here is my main and the buffer implementation: #include &...
1
vote
2answers
34 views

How to store multiple strings in a 2-D array? [duplicate]

I want to write a C program that stores a bunch of sentences while it's running and prints them out at the end of the program. Here's what I wrote: #include<string.h> #include<stdio.h> ...
1
vote
1answer
56 views

while loop for a game in C?

I have a word guessing game which I needs to repeat until the user types Q:. Generally, the answer is in a format A: answer. The game's using sockets! Instead of while(1), I tried using while(buffer[...
-2
votes
1answer
29 views

How to assign char[] to null inside the struct

I m trying to assign null to char name[] inside the struct; however, it not working #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <fcntl.h> #include <...
1
vote
0answers
65 views

Comparing Strings C (Socket Programming)

I am making a game where the answer is stored in client_challenges->answer while the client inputs the answer (which is stored in buffer) in the following format: A: myanswer If the answer starts ...
0
votes
1answer
29 views

Am having difficulties with linked lists

I am trying to learn linked lists and I am just making this program for practice. It contains several linked lists made from two structs. Everything from the struct letterLink works fine (typedef ss) ...
0
votes
2answers
23 views

(C/C++) fscanf_s Missing Integer Arguments error When Reading in Chars to Array from txt file

First Post, will do my best to follow guidelines and make this a proper setup. If ANYTHING is needed, let me know! The error in VS 2019 is "C6064: Missing integer argument to 'fscanf' that ...
-2
votes
1answer
27 views

How can I write a function whose prototype should be 'void convertstring(char *)' to convert lower case to upper case in C?

This is what I've written #include <stdio.h> void convertstring(char *str[]) { int i; for (i = 0; *str[i] != '\0'; i++) { if (*str[i] >= 'a' && *str[i] <= 'z') ...
0
votes
0answers
41 views

convert hex string command into byte array in C [duplicate]

Hi I am trying to to write a hexadecimal command into serial port, where i need to convert a hex string into particular byte array format in C, having problem with parsing escape character. please ...
-1
votes
1answer
29 views

Can string of character be changed to integers or characters? [on hold]

In my program, I want to scan in string of characters or number to use in if statement but it doesn't work. I tried to use atoiformula. However, it only changes the numbers not the characters. Does it ...
0
votes
0answers
43 views

How to correctly use strsep() to parse an array?

I'm trying to implement a function that takes a string to parse and delimiter string as inputs, then returns a char array containing these parsed elements including empty chars if two delimiters are ...
0
votes
2answers
41 views

Manupulating and accesing char *s pointer variable (string) using another pointer variable char *c - C

I've hit a roadblock, when trying to manipulate strings when "storing" them as pointer variables. // Sample code to input a string till line break is encountered, later re-allocating to save space ...
0
votes
0answers
12 views

Problem while taking string as input in 2D array [duplicate]

This was the question in my C programming assignment: Write a C program to enter name, age and marks of ‘n’ students for five different subjects and print the top scorer. My Code: #include<...
0
votes
3answers
59 views

How can I delete the first entries from a string

This is my task: Write a program that reads a string w of maximum length m = 100 and two indices a; b element of [1; 100], with a smaller or equal than b from the keyboard. Then, the substring ...
3
votes
1answer
41 views

String format in C %*s

I saw somewhere a portion of code in C char name[51]; int group = 0; scanf("%*s %50s %*s %d", name, &group); printf("%s / %d\n", name, group); If we introduce "Name:Smith Group:7" it ...
-1
votes
3answers
43 views

How to copy string from a single dimensional array to 2d array in c?

I am trying to copy same characters from an single dimensional char array to each row of a 2d array,but I cant any output. Expected output: abcd abcd abcd ...
3
votes
3answers
79 views

Reverse words of string by recursion

I'm trying to write a C function that takes a string, and return a new string with reversed words. For example, entering "How are you" should return "you are How". The following is my trial: #include ...
0
votes
3answers
51 views

Find multiple characters in string AFTER substring [duplicate]

So I have this problem, where I have a string like this with points: "TaskA:55 TaskB:23....." etc. Is there a function with witch I can get the points from this? I'm familiar with strstr, but that ...
0
votes
1answer
33 views

how to fix code that prints the code read in a file with a double char pointer

This code is intended to read the content of two files and to store them into two double char pointers, so that each element of each array stores a line of each file. When reading the files, I tell ...
-2
votes
0answers
42 views

'gets' function of C behaves weird in two scenerios [duplicate]

I am running some programs in C using gets. I noticed this: 1. When I write this piece of code-> #include<stdio.h> int main(){ char *str; gets(str); puts(str); return 0; } ...
-5
votes
3answers
85 views

Can I change the datatype of previously declared variable in C?

I have declared a string and using malloc function I allocated the memory... Now I want to change this string into a floating type. char *str; str=malloc(sizeof(char)*10); strcpy(str,"123.4"); float ...
-3
votes
0answers
24 views

Segmentation fault in “string parse” program [duplicate]

Program seems to fail parse string constant: [email protected]:~/c_code$ ./parse_string "a b" 3:a b 3:0x558c2789f360 1:0x558c2789f361 n=2 a b 18:Parse this string! ...
-4
votes
1answer
65 views

How to dereference a string pointer

I'm having issues getting the desired behaviour out of my code. I'm new to the C language (although I usually program in C++ so I'm sort of familiar), and I'm unsure where to go with my issue. In the ...
-1
votes
2answers
38 views

How can i read defined values from a string in python, like i can do in C with scanf

I have a String, which is formatted as following str="R%dC%d" for example Str=R150C123 and i want to save the numeric values in a variable for example in C Language this would be as following: int c,...
2
votes
1answer
45 views

Custom read line function

I tried to write a simple read_line function like following. #include<stdio.h> #define MSG_LEN 60 void read_line(char *,int); int main(){ char msg_str[MSG_LEN+1]; read_line(msg_str,...
0
votes
1answer
35 views

Caesars cipher - Conditional jump or move depends on uninitialised value

i have a problem with my school project. Project is about Caesar's cipher, the program input includes message length, encrypted message, and poorly intercepted message (several characters are correct)....
2
votes
4answers
114 views

How can I execute an 'if' statement only once per iteration in a for loop?

Assuming there are no duplicate words in either list, I would like to compare the words of listA with the words in listB. If there is a match, I want to print the word that matches and compare the ...
1
vote
1answer
37 views

How to append tokens to a string variable in C?

So I have the following code: //Get the line fgets(line, MAX, stdin); //Remove trailing new line character line[strcspn(line, "\r\n")] = 0; //Count number of tokens int tokenCounter = 1; for (...
-1
votes
1answer
38 views

C strtok() not tokenizing correctly?

i've been trying to figure this out for a while now and i have absolutely no clue how to fix this. I have a pretty decent sized project and i'm using strtok countless times wihout any problems but it'...
-3
votes
0answers
48 views

Issues in C program to store a list of people over 50 years of age [closed]

I started programming now and I'm doing an exercise where I need to enter 10 names and ages, and store them to be displayed later for those over 50 years and 21 years old. I started the code and went ...
0
votes
1answer
23 views

How to store words from a file in a two dimensional array in C

I am trying to read a file like: mother mama, father papa, apple mar, ... And I would like to store those words in an array of chars A[10][2][12] so the words : "mother" will be in A[0][0] "father" ...
0
votes
1answer
34 views

Replace ending of string in C using backwards for loop

I am trying to replace the last part of a string using a for backward for loop iterating for every element of the original string and assigning the first (last elements because I am iterating ...
-3
votes
1answer
30 views

Why doesn't my first gets() work? I have some of them and codeblocks always forgets the first one?

I'm using gets() cause it's a jomework and we are told to. It acts like I'd have no gets(&a)... ` char a,b,c; switch(x); case '1':printf("Please enter the author\n"); ...
-8
votes
1answer
43 views

Writing a Nonrecursive and Recursive Function for a given Task [closed]

I am now learning about recursive functions aka functions that call themselves in Python and C. And I'm curious how to write a nonrecursive and recursive function that determines how many times a ...
-1
votes
1answer
29 views

count a character in a string (C) - question

I have to write a program in C which finds the number of apparitions of a character which I choose. This is my code: Why if I remove de bold line the program does not work anymore ? I mean I don't ...
1
vote
1answer
64 views

I can't input a string with spaces

I'm writing a program and I need the user to input a line like this (1, Stelios, 1.81, Greece). First thing I thought was use gets() because I want to accept space inputs . After a few tries ...
0
votes
3answers
70 views

Array entries being overwriten in C

I want to convert an integer array to a string array. For example, if arr[] = {1, 2, 3, 4, 5}, I want to end up with arr2[] = {"1", "2", "3", "4", "5"}. This function works fine until it exits the for ...
-1
votes
2answers
40 views

C - Replace multiple consecutive occurences of a character with single occurence

How can I replace multiple consecutive occurences of a character with a single occurrence in C? For example, if I have a char myString[]="??hello?world????" I would like to have the output as ?hello?...
1
vote
2answers
39 views

Create protocol line from string removing \n and \0

We have to create a text message p2p applicattion with C. We've already done the p2p connection using the TCP interface, but we're having trouble to implement a protocol to send and read messages. ...
0
votes
1answer
38 views

Problem to start a nested for loop in C to iterate over arguments

I am puzzled by the following code, which aims to iterate over all string arguments given and prints only the vowels. #include <stdio.h> #include <string.h> int main(int argc, char *...
-3
votes
4answers
65 views

why does sizeof(*pointer) gives output as 1?

#include <stdio.h> int main() { char *str1 = "Abcde"; char str2[] = "Abcde"; printf("sizeof(str1) = %d, sizeof(str2) = %d sizeof(*str1) = %d", sizeof(str1), sizeof(str2),...
1
vote
1answer
58 views

Difference in declaring strings in C

How are these two different in C? char str[] = "xyz"; // statement 1 //and char str[4] = "xyz"; // statement 2 According to my understanding, the first one assigns a pointer to a ...
-1
votes
2answers
29 views

Program to find sum and if entered 'y' then repeat the process using do while loop

Here a print message "Do you want to run again?" is asked, if we enter "y" then program will repeat. I tried this code #include<stdio.h> int main() { int a, b, c; char ch; ch = 'y';...
0
votes
1answer
28 views

C: Finding a specific character in a string

I am trying to write a program that searches for the first occurance of a specific character in a string. But no matter what character i type in the number the program gives back is the number of the ...
2
votes
1answer
55 views

What is the difference between two ways to manipulate strings in C?

I want to copy a string "str" to p . First I used the code I commented out, but the output was empty. So I tried the code that is below the commented area, and it worked. What is the difference ...
0
votes
0answers
30 views

how to store the names of paths in a list or an array of strings in C?

I have the following code to find files recursively in a folder. The arguments I am prompt to enter are path where files are located, and 2 the "wildcard" of the files I am trying to list: #include &...