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
-1
votes
2 answers

how to recognize string with color code with strncmp in c?

I have two programs in C: a client and a server. I'm not going to develop all the details of the code, things work fine. Except for this point: I want my server to send colored acknowledgment messages and my client to identify them. On the server…
-1
votes
2 answers

better way for string comparison

I have a JSON parser that sends a callback for every parsed key-value pair. I then use strncmp with statically allocated strings in my program to check if the field matches any of the fields I am interested in. I have now ended up with a dozen of…
rookie
  • 1,168
  • 3
  • 14
  • 25
-1
votes
1 answer

c- strncmp "end" of a while doesn't kill the cycle

in this program about shared memory(Producer/Consumer) with semaphores(on DEBIAN) when I use the strncmp function with the string "end", in order to turn on 0 a flag(running) to kill a while cycle,strncmp doesn't recognize the word end that I insert…
amcnvbfgh
  • 1
  • 3
-1
votes
1 answer

Prevent characters from being written out in file in c

I'm trying to write a program in c to write out some strings, words, characters,etc... The gist of the program is to allow everything to be written, however the first two bytes of the program cannot contain the character "MZ". I'm new to c and…
Nam Vu
  • 1,727
  • 1
  • 11
  • 24
-1
votes
1 answer

Count how many times an IP number appears in a text file - C Program

I have a log file of 10 hits e.g. one line is: 127.0.0.1 - - [10/Oct/2007:13:55:36 ­0700]"GET /index.html HTTP/1.0" 200 2326 "http://www.example.com/links.html" "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.1.4322)" The format of…
hturner
  • 215
  • 3
  • 7
  • 19
-1
votes
3 answers

strncmp gives segmentation fault when comparing two strings

I am trying to write a function which compares first two digits of a number, and since itoa is not available, I am using sprintf as found by googling previously to first convert number to string and then compare each digit. For some strange reason,…
-2
votes
2 answers

strncmp() function vs !(strncmp()) function

I'm programming a lock where to unlock it you have to insert a PIN code in a Keypad. I have the following variables: char password_init[4] = {'1', '2', '3', '4'}; //initial password char password[4]; When the user press a key in the keypad, that…
-2
votes
1 answer

Strncmp issue in a C program

With the help of this community I have manage to write a code for taking a snippet out from an input xvg file that I need. It's almost working for me but it has a slight issue with strncmp.I want to get a part of this input file file say 1000 to…
Vikas Dubey
  • 19
  • 1
  • 5
-4
votes
3 answers

strncmp doesn't return 0 on equal strings

Shouldn't the strncmp("end",input,3) == 0 return 0 if the input is end? It returns a number > 0 though. #include int main(void) { char *strArray[100]; int strLengths[100]; char input[100]; int flag = 0; do { …
Stelios Papamichail
  • 955
  • 2
  • 19
  • 57
-6
votes
2 answers

strcmp refuses to work

I've tried everything, yet strcmp (as well as strncmp) always give a value other than 0, both with and without using pointers, as well as inside and outside functions. What should I do? The point of the program is to create a student data system for…
Tasos500
  • 107
  • 2
  • 11
1 2 3 4 5
6