All Questions
70 questions
1
vote
1
answer
107
views
Word Count in C
I have a word count program in C that excludes special characters and number digits:
int main(){
char str[100];
int i, j = 0;
int len;
char choice;
do {
printf("...
1
vote
1
answer
77
views
Longest common substring with restrictions
I have a function that finds and prints the longest common chain between two DNA chains. However I want to add some checks so my program can ignore characters that are not bases ('A', 'T', 'C', 'G')
...
2
votes
1
answer
83
views
wcstok causes segmentation fault
I'm writing program that splits cyrillic text from stdin and prints it line by line. After reading text using fgetws i am getting Segmentation fault. Debugging with gdb returns this:
Program received ...
1
vote
3
answers
76
views
Separating a long string into individual words in C
What I'm trying to do is, given a string (say "This is a string") write a code that could take it and put each word in a separate element of an array ("This", "is", "...
1
vote
4
answers
115
views
strtok function c element considered problem
When I try to split a string with a delimiter, the strtok function doesn't consider empty strings and I would like to know how to fix it.
For example, in my case, I have to split strings like "a-...
0
votes
2
answers
114
views
reading input from .txt file in C
john smith 21 VETERAN 1
I have a .txt file writing this . I want to read this .txt file and take john smith as a variable . but I can't read with whitespaces.
edit: I want to take john smith and ...
0
votes
1
answer
117
views
Count Frequency of a Substring in a String
Given a string T and a pattern P which is also a string. Find the number of occurrences of P in T.
Input
Line 1: contains string P (length is less than or equals to 10^5)
Line 2: contains the string T ...
1
vote
1
answer
54
views
Why does the following code not work as intended
I have a string and I want to split it into words. The code works when the string passed ends with a space, but not otherwise
CODE:
void form_rule2(char * str)
{
int num_words=0;
char word[20];...
5
votes
1
answer
131
views
What does ranges::starts_with do with C-style string argument(s)?
The following code prints 1010
#include <iostream>
#include <range/v3/algorithm/starts_with.hpp>
int main () {
using namespace std::literals;
std::cout << ranges::...
0
votes
3
answers
93
views
C Program returns unexpected output
This code is supposed to determine if a word is present in a sentence or not. I tried with the input sen:"my name is", search:"name", but it displays not found. Please help me. ...
0
votes
1
answer
64
views
strstr not working with needles shorter than 3 char
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char* findSequence(char s[], char ch, int n){
int i;
char*ptr;
char needle[n];
char*npdr=&needle;
...
0
votes
2
answers
146
views
input three strings into function, function needs to return the longest substring that is in all three strings
I have written the code already, and its pretty much finished, but while testing it, it would sometimes faulter(very rarely), and I cant quite figure out why.(Input three strings into function, ...
-1
votes
3
answers
43
views
How do I create an array based off an existing array where each element of the new array copies the original array until the first tab character in C
I have an array of strings read from a file. I'd like to take each string in the existing array and copy it to a new array unit the first instance of a tab character, and then move to the next element ...
0
votes
1
answer
210
views
I can not understanding this portion of code for this token identification program
I have got this code reference from a website and practicing with this.
When I am trying to working with malloc() function then how we getting the value from right-left+2
// Extraction string
char* ...
0
votes
2
answers
883
views
C++ : Member reference base type 'char *' is not a structure or union
void find_substring(char * str_for_search_in, char * substring)
{
bool flag = false;
for (int i = 0; i < strlen(str_for_search_in) - strlen(substring); i++)
{
if (...