Questions tagged [strncmp]

The strncmp function is a string comparison function found in languages like C and C++. In contrast with strcmp, the strncmp function takes a third argument denoting the maximum length of the strings. This is used to prevent out of bounds errors.

85 questions
0
votes
3 answers

Strncmp: Unusual segmentation Fault

I'm really new to C, but I've been writing C++ for a while. I'm writing a client sever chat program. I need to prompt the user with a couple of different options at the beginning of the session, after they've entered a username. At first I was…
0
votes
2 answers

Use of strcmp() to read data from a client not working as expected

I am following an exercise where I need to set up networking between a client and server and have them "talk". I need to check for specific responses from the client and then have the server act accordingly. To read data from the client, I am using…
user1720897
  • 1,216
  • 3
  • 12
  • 27
0
votes
1 answer

For the life of me, I can't compare the first character of this array

All I want to do is pass in a char* buffer and compare that to a literal string "@" -- why is this so difficult for me. char* buffer = "@3702"; string b(buffer); string c("@"); if (strncmp(b.c_str(), c.c_str(), 1) == 0) { …
MrDuk
  • 16,578
  • 18
  • 74
  • 133
0
votes
3 answers

Can someone explain why this function is the way it is?

I was looking at functions from GNU C library, glibc-2.18, and this is the code I found for strncmp.c Looking at it I don't understand why it's written this way. Is this loop unrolling? Why not use 5 or 10 instead of 4? And why did they write like…
2013Asker
  • 2,008
  • 3
  • 25
  • 36
0
votes
3 answers

comparing strings c++ with wildcard values

I've been lurking around here for a long time, thank you for all your help in the past, even if this is the first question I've had to ask. I'm trying to make a simple database program, and I am stuck the search requirement for it. When searching,…
0
votes
2 answers

How to compare user input string with string in a file in C

So Im trying to make a program that searches in a file for a word that the user inputs. If theres a match, it say "FOUND IT", if it couldnt find anything, it says " COULDNT FIND ANYTHING" (obviously :p). Im not clear at how to scan the file for the…
raz
  • 75
  • 2
  • 12
0
votes
4 answers

strncmp() gives a false positive

I have been expirencing an issue with strncmp and getline... so a i made a little test app. strncmp gives false positives and i can't figure out what i am doing wrong. this is the program #include FILE *fp=NULL; char uname[4]="test"; char…
MrBlarg64
  • 13
  • 1
  • 2
0
votes
2 answers

strncmp in Linked List

This program should allow the user to input some names (until the user wishes to continue.) and then display those names in ascending order. I have used the strncmp function in comparing the char arrays. But when this is run, only the 1st and last…
Dee
  • 3
  • 4
0
votes
2 answers

Long spacing after loading buffer from text file

Okay, this is just part of a simple client-server program. Right now I'm just trying to implement a simple login checker. Inside the Users.txt file is just one line: "Bryan". So far I cannot get strncmp to produce a positive response. #include…
gwar666
  • 13
  • 1
  • 4
0
votes
1 answer

Why is strncmp not comparing? Socket programing C

I'm trying to parse the received data from a client in a server. The server have to send back a message according to what the client sent before. But I can not make the strncmp function compare the strings. It always get to the else and my server…
netfreak
  • 63
  • 2
  • 4
  • 9
0
votes
2 answers

using strncmp c-style string function

I have a string and I'm trying to find out if it's a substring in another word. For instance(pseudocode) say I have string "pp" and I want to compare it (using strncmp) to happy apples pizza and if it finds a match it'll replace the "pp" with…
ShadyBears
  • 3,955
  • 13
  • 44
  • 66
0
votes
5 answers

strncmp not matching correctly

I have no idea how to work with strings in C: here's a part of my server: The break never gets called, even though I supply the character '/' through telnet. Ideally, this would buffer up the string called get by adding the string ch to it over and…
stackOverFlew
  • 1,479
  • 2
  • 31
  • 58
0
votes
2 answers

C++: Funny string comparison crash

I'm trying to take in a simple command line argument in a C++ program to trigger different program behavior - when you include a "y" (or any string starting with y - I don't really care) the program displays some intermeadiate results. When I run…
fatman
  • 65
  • 6
-1
votes
1 answer

Write a program that reads a short string and a longer string and checks if the longer string starts with the letters of the short string. Use strncmp

I need help getting this code to work. Could someone tell me how to properly use strncmp and how to get this to work? Example: Enter first string: john Enter second string: johnson johnson does start with john This is my code here: #include…
-1
votes
1 answer

my strncmp isnt working for two 2d arrays

I am trying to compare and find matches in my two arrays but it is not working can any one help? const char spam[30][30] = {"cash bonus","earn money","fast cash","free access","free gift","free membership", "giveaway","million…
sonya
  • 1