Skip to main content

All Questions

Tagged with
Filter by
Sorted by
Tagged with
1 vote
1 answer
235 views

Printing all possible strings with given characters in dictionary order

Problem description: He handed you a string and asked if you could make as many different words as possible using its characters. Excited to give it a try, you got to work. It felt a bit like solving ...
Phani P's user avatar
  • 11
0 votes
1 answer
248 views

Remove stars question from Leetcode (2390)

Problem: You are given a string s, which contains stars *. In one operation, you can: Choose a star in s. Remove the closest non-star character to its left, as well as remove the star itself. Return ...
Inderjeet's user avatar
-1 votes
1 answer
49 views

How can I make an algorithm that finds and counts the same words in the a string using c?

I have code that finds the same words with help specific word. Now, I try make code that finds and counts the same words in a string like that: "hello hello hello bye bye" => hello - 3, ...
emblox's user avatar
  • 37
1 vote
2 answers
78 views

How can I add counter to remove duplicate words in a string algorithm?

I have this algorithm that removes duplicate words in a string: int main() { char str[100], word[100], doubleArr[10][30]; int i = 0, j = 0, k = 0, len1 = 0, len2 = 0, l = 0, n, c = 0; ...
emblox's user avatar
  • 37
1 vote
1 answer
238 views

print string based on the frequency of character in C

I was solving the question of leet code in C Question: Given a string s, sort it in decreasing order based on the frequency of the characters. The frequency of a character is the number of times it ...
horsemann07's user avatar
0 votes
1 answer
54 views

A function that sorts given array of strings using strcmp function in C

I've been trying to write a function named sort that takes function and its size as argument and sorts the array using bubble sort in C. But mine doesn't work most of the time. Here's the code: #...
Nectar's user avatar
  • 3
0 votes
1 answer
248 views

How to count spaces and pass characters or newline?

I was writing a tool that replaces enough spaces with tab, but it counts more spaces than expected. Algorithm should count spaces until seeing character or newline, if there is a character or newline, ...
Ali Koca's user avatar
-3 votes
3 answers
321 views

Implementation of Log function but for numbers represented as a string C [closed]

Is there a way to implement the log function witch works for string numbers without converting the string to a int? example of string number: char *stringNumber = "432" the string represents ...
El45n's user avatar
  • 1
2 votes
2 answers
196 views

strncpy making weird output

I'm trying to make an algorithm for strncpy I read how it work in the manual and made my algorithm then I made a test to see if there's any difference between my ft_strncpy and the real strncpy #...
AzerSD's user avatar
  • 168
3 votes
1 answer
956 views

How to implement copy propagation? [Design]

In compiler theory, copy propagation is the process of replacing the occurrences of targets of direct assignments with their values. A direct assignment is an instruction of the form x = y, which ...
Grace Mathew's user avatar
0 votes
2 answers
124 views

Every k-th digit cyclic problem using strings in C

Given some number in a form of string, I want to extract every k-th number from it. Then I go through the remaining string and extract every k-th number again. The thing I get as a result should be ...
Sgg8's user avatar
  • 201
0 votes
1 answer
117 views

My quicksort algorithm is giving me a trace trap, how can I fix it?

So currently I am trying to make a quicksort algorithm for an array of strings (to sort them alphabetically) since I can't use the qsort() function for this exercise and I also cannot allocate memory (...
DoubtLord's user avatar
0 votes
0 answers
74 views

Check if the String is palindrome using recursion not working even if the logic of the code seems to be correct

This is my code code for checking if the given string is a palindrome or not, using recursion: #include<stdio.h> #include<string.h> #include<stdbool.h> bool ispalindrome(char A[],...
PRIYANKA CHETTRI's user avatar
4 votes
6 answers
802 views

How to reduce time complexity in traversing a string?

I was solving a problem to find number of such indexes, a, b, c, d in a string s, of size n made only of lowercase letters such that: 1 <= a < b < c < d <= n and s[a] == s[c] and s[b]...
rohan843's user avatar
  • 141
-1 votes
1 answer
120 views

Returning Specific substring's pattern from given String?

I want to implement a C/C++ function that its input is an array of chars, like this: char string[]="abccccfffcccccc" and then search for a specific string pattern, then return an array of ...
TonyMamy's user avatar
0 votes
0 answers
28 views

Checking the logic: Number of words of each length [duplicate]

I am trying to write a program in C to find the number of words of each length in the input. I am aware this question has been asked before but it is not a duplicate as I want to find the error in my ...
Sahiba Arora's user avatar
1 vote
2 answers
1k views

Difference b/w using i<strlen() and str[i] != '\0'

When I use for(i=0;i<strlen(s);i++) then I am getting time limit exceed error. And When I use for(i=0;s[i]!='\0';i++) my code get successful submit. Why? I am also providing link of question from ...
Aditya Ojha's user avatar
0 votes
1 answer
40 views

Check if a string contains a specific number of given values

I am trying to decode a message provided as a morse code via command line argument. If the provided string contains 7 spaces it means that I need to print a space to the decoded string. This is the ...
Karyna's user avatar
  • 205
1 vote
3 answers
86 views

String operations vs Array operations in C

I was solving the permutations of a string problem - Given two strings s1 and s2, write a function to return true if s2 contains the permutation of s1. In other words, one of the first string's ...
Khalidos's user avatar
1 vote
0 answers
174 views

Boyer Moore replace more than one pattern

I am working on a string search and replace project. I can only change 1 of the target pattern in the sentence. But I can find both. Example: just do it. you will do it. find: do replace: think ...
agahpars's user avatar
2 votes
2 answers
299 views

How can I check if a string is a whole number in C?

I have recently encountered a problem in which I had a string array inputted by the argv[] to check if it is a whole number or not. I tried to use isdigit(). However, it returns "20x" as a whole ...
carvalho28's user avatar
1 vote
3 answers
8k views

calculate sum of all numbers present in the string

I am solving this problem: Given a string str containing alphanumeric characters, calculate sum of all numbers present in the string. Input: The first line of input contains an integer T denoting ...
Laveena's user avatar
  • 97
1 vote
3 answers
2k views

Count number of substrings having only vowels

I wrote a code to find the vowel substrings of the given substring. but i need help in counting the substring thus formed? code: #include <stdio.h> #include <string.h> #include <...
simon cowell's user avatar
1 vote
0 answers
166 views

How can I get a new string from other strings without simply concatenating them?

I want to generate a new string from other strings without using concatenation functions or crypto algorithms (md5, rsa, aes, sha256). Specifically, I want to take 2 or 3 (or more) MAC addresses and ...
Giordano Cechet Moro's user avatar
-1 votes
2 answers
1k views

Number of characters compared during naive string matching

I've been asked to find the number of characters that are compared during naive string matching. This was the function we were asked to implement: // Count the number of characters compared while ...
bobthebuilder's user avatar
-2 votes
1 answer
84 views

The program returns some weird and incomplete string

I am trying to write a function that delete whitespaces from a string but the output is not reasonable at all. I need help fam! Code: char* deleteSpace(char *String, int n) { int i; char* ...
Logic's user avatar
  • 1
0 votes
1 answer
269 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 ...
user avatar
-1 votes
2 answers
73 views

How to get the length of the relevant palindrome of a word in a string?

I need to get the length of the palindrome of the word in a string. Ex. tomyot length =2. I wrote the following code but it doesn't work. #include <stdio.h> #include <string.h> #include &...
Avishka Dambawinna's user avatar
0 votes
2 answers
319 views

Reading text file from terminal line?

So I understand that to read and print out a line of text you can just use printf, scanf and type it out. However what if I want to print out a text file without typing them out in terminal? And I don'...
oog1119's user avatar
  • 27
6 votes
7 answers
1k views

Most efficient way to find if a string is mixedCase

Suppose I have very long strings and I want to see if a column is allLower, allUpper, or mixedCase. For example with the following column text "hello" "New" "items" "iTem12" "-3nXy" The text would ...
user avatar
-1 votes
5 answers
3k views

Find the first position of a character in string C

Find the first position of a character c in string Here is my code of the function int char_index(int c, char *string) { int flag = 0; int i = 0; int index = 0; for(i = 0; string[i] ...
User21749's user avatar
-2 votes
1 answer
42 views

String Values is getting the values from the other string

I'm having problem on string values, i am generating on the function "gerarconta" that make random numbers for the following variables: "cb->cocom[numcontas].senha" with 4 numbers as characters, "...
Jordão Qualho's user avatar
2 votes
2 answers
927 views

Algorithm in C - who is the winner team

I need to store data from a tournament. I need to know how many teams will play(n) and the number of games they will play (n!). Then, the team's names and their results. Something like this: Input: ...
MadPat's user avatar
  • 53
0 votes
1 answer
73 views

Can someone help explain what this C algorithm is doing?

I have been looking at this C code but am not sure what exactly it is doing. I don't understand the use of multiple if statements of finding statements. int f(char *s) { char *p = s; int c = 1; ...
Sarthak Rakhra's user avatar
-1 votes
1 answer
425 views

Is this algorithm correct for finding period of a string?

An answer to this question cites page 340 of "Text algorithms" by Crochemore and Rytter for a linear-time algorithm to compute the period of a string. However it's quite complex, and the following, ...
R.. GitHub STOP HELPING ICE's user avatar
-2 votes
2 answers
510 views

C: How to read multiple string fragments and print #of fragments and #of chars [closed]

So I have an input of : aaaaaaaaaa aaaaaa aaaaaaaaaa aaaaaaa aaaaaaaaaaa aaaaaaaaaaa (with each group of a being 1 fragment) and I want an output of : 6 fragments read, 55 characters in total How ...
BenJi's user avatar
  • 15
3 votes
4 answers
4k views

C base conversion from decimal to ternary

I'm converting an integer value to a ternary number (which is a String). I suspect there should be a better way to achieve this with less computational effort. My algorithm directly implements the ...
elanonrigby's user avatar
-2 votes
1 answer
141 views

segfault appending a empty string C

I am trying to append a string with a specific char. I am getting a segfault from what I believe is because i am trying to append to a memory address and I dont know how i would go about changing this....
Jeffrey Hennen's user avatar
3 votes
1 answer
856 views

Merging algorithm to sort two string arrays while merging

I have made a program with two string arrays. List 1 & List 2. they are unsorted. The program runs and the two lists are individually sorted using a bubble sort algorithm. Then they are merged ...
love2code's user avatar
0 votes
2 answers
75 views

Merging two sorted string arrays in C

This is a program that takes two unsorted arrays DTA & DTB. sorts them using a bubble sort method and then using a merge algorithm, merges the two arrays into a bigger array (big_array). The ...
user214's user avatar
2 votes
4 answers
2k views

Sorting an array of strings with Bubble sort

Any help would be greatly appreciated. I am trying to sort 12 strings alphabetically which are contained in an array using bubble sort with the following code: #include <stdio.h> #include <...
Mick jAGGER's user avatar
0 votes
2 answers
376 views

Permutation of a string so that the patterns match

The question is to count how many permutations of a string B have an equivalent pattern into a bigger string A. For example, if A="aabbccd" and B="xx", then it should print 3, since "aa", "bb", "cc" ...
Juan Lopez's user avatar
-2 votes
2 answers
6k views

Counting number of words which starts with 'A' letter? - C

I just started learning C after Java, so it's a little bit confusing to me. I tried to write a program with idea of counting the numbers of words which start with 'A' letter. The problem is that it ...
Cruel World's user avatar
-1 votes
1 answer
47 views

C concatenating strings won't work

int main(int argc, char** argv) { char data[1024]; data[0] = '\0'; for(int i = 1; i < argc; i++){ strcpy(data+strlen(data), (argv[i] + 1)); } strcpy(data+strlen(data), ...
Klausar's user avatar
  • 119
0 votes
1 answer
280 views

C program that splits string into tokens and counts vowels

I am trying to do a C program that splits string into tokens and counts vowels in each word found; if there are more than 2 vowels, show the word. That's what I tried to do. I think strtok is the ...
Seth Hexflame's user avatar
-1 votes
3 answers
88 views

I want to search an element of the string str in the string s but when I'm trying to search anything(e.g. str[1]) in the string s, it returns 0

#include <stdio.h> #include <string.h> int lsearch(char a[],int l,int h,char p) { int i=l; for(i=l;i<=h;i++) if(a[i]==p) return i; else return 0; } ...
Utkarsh Pandey's user avatar
0 votes
0 answers
42 views

Getting multiple strings with repeated character [duplicate]

The problem is getting all possible combinations of that string with permutations. The solution must be recursive since it uses large values. For example the number can be ...
King Tsunamy's user avatar
0 votes
1 answer
529 views

Wildcard matching strings

I am trying to write a function bool match(char pattern[], char expresssion[]) which checks if the pattern matches the expression. If * appears in the pattern, it can be matched with any string - the ...
Aemilius's user avatar
  • 676
0 votes
3 answers
265 views

Searching for block of characters (word) in a text

I want to search for a block of characters (word) in a text. For example, I have the next text "Hello xyz world", and I want to search for "xyz ", note the space after the word. // ...
Lion King's user avatar
  • 33.8k
-2 votes
1 answer
1k views

C - how to compare index on 2 string?

i have 2 string; string1[20] = "ab cd efgf"; string2[20] = "mn go jpfgt"; Need to find the first letter in string1 that appears in string 2 and after print the place(index) and the letter In each of ...
B RAMI's user avatar
  • 19

1
2 3 4 5