strcmp Questions

3

Solved

In the responses to the question Reading In A String and comparing it C, more than one person discouraged the use of strcmp(), saying things like I also strongly, strongly advise you to get used...
Juanitajuanne asked 22/6, 2014 at 16:54

1

Apologies in advance for the elementary nature of the question. I am trying to use the strcmp function to test two strings for matching characters. I reduced the issue to the simple code be...
Typeface asked 24/5, 2014 at 19:5

2

I need to make some modifications to the the C standard library (glibc) in order to get some performance improvements. Specifically, I am going to be writing some specialized versions of some of th...
Newsom asked 20/8, 2013 at 17:29

2

Solved

I wonder my code works perfectly fine either using strcmp or simply == in C++ for comparing 2 char arrays. Can any one justify the reason of using strcmp instead of ==;
Mer asked 22/3, 2014 at 3:13

5

Solved

I am learning about strcmp() in C. I understand that when two strings are equal, strcmp returns 0. However, when the man pages state that strcmp returns less than 0 when the first string is ...
Remy asked 5/10, 2011 at 3:43

4

Solved

I am new to C and am still a bit confused about how to use strings via character arrays. In my C program, I am accepting commands from the user: char command[20]; scanf("%s",command); Of course...
Laterite asked 2/8, 2013 at 21:31

6

Solved

By my understanding, strcmp() (no 'n'), upon seeing a null character in either argument, immediately stops processing and returns a result. Therefore, if one of the arguments is known with 100% c...
Pansophy asked 14/2, 2013 at 22:11

2

Solved

Normally strcmp is used with two arguments [e.g. strcmp(str1,"garden")], and it will return 0 if both are the same. Is it possible to compare part of the input, say the first five character of the...
Postbox asked 12/12, 2012 at 3:32

6

Solved

I'm trying to compare two strings. One stored in a file, the other retrieved from the user (stdin). Here is a sample program: int main() { char targetName[50]; fgets(targetName,50,stdin); cha...
Apothem asked 8/3, 2010 at 21:13

4

Solved

For unknown reason, result of running my C program is quite unexpected. I think that it has to be some kind of a beginner mistake, however I can't find out really, where is it. #include <...
Ashton asked 24/8, 2012 at 11:21

6

Solved

I decided to find the speeds of 2 functions : strcmp - The standard comparison function defined in string.h xstrcmp- A function that has same parameters and does the same, just that I created it...
Overstep asked 17/7, 2012 at 12:31

4

Solved

I have a basic program that compares two strings : #include <string> #include <iostream> using namespace std; int main (int argc, char *argv[]) { if(strcmp (argv[0],"./test") != 0)...
Deonnadeonne asked 21/6, 2012 at 12:13

4

Solved

I have the following: int findPar(char* str) { int counter=0; while (*str) { if(str[0] == "(") <---- Warning { counter++; } else if (str[0]== ")") <---- Warning { counter--; } if ...
Shaver asked 7/5, 2012 at 23:44

2

Solved

I need to search for two particular words in a file line by line and if they exist, print "Found!". This is file.txt (has four columns) bill gates 62bill microsoft beyonce knowles 300mill entert...
Stamp asked 20/4, 2012 at 3:17

6

Solved

Out of professional curiosity, what is the safest / fastest / most efficient way to compare two fully numeric strings in C? #include <stdio.h> #include <string.h> #include <stdlib.h...
Zinovievsk asked 17/6, 2011 at 18:8

3

Solved

PHP's documentation on this function is a bit sparse and I have read that this function compares ASCII values so... echo strcmp('hello', 'hello'); //outputs 0 as expected - strings are equal. echo...
Galluses asked 15/2, 2012 at 7:41

2

Solved

I have written a function template and an explicitly specialized templated function which simply takes in 3 arguments and calculates the biggest among them and prints it. The specialized function ...
Cashier asked 14/10, 2010 at 15:37

2

Solved

I am using strcmp in following ways Passing char[] array names Passing pointers to string literals but, the second result in seg fault. even though i have confirmed that pointers point to correct...
Tenderloin asked 10/6, 2011 at 4:15

8

Solved

I was reviewing some code and I saw someone do a if (0 == strcmp(foo,"")) I am curious because I think it would be faster to do a if (foo[0] == '\0') Is this correct or is strcmp optimized e...
Rotary asked 1/6, 2011 at 14:47

12

There's something really weird going on: strcmp() returns -1 though both strings are exactly the same. Here is a snippet from the output of the debugger (gdb): (gdb) print s[i][0] == grammar->s...
Nerland asked 24/12, 2009 at 20:0

3

Solved

When I run the following code: #include <stdio.h> int main(int argc, char *argv[]) { int p = 0; p = strcmp(NULL,"foo"); return 0; } I get segmentation fault. echo $? says 139. But w...
Barricade asked 8/2, 2011 at 12:14

4

Solved

Is there an easy way to find a smaller cell array of strings within a larger one? I've got two lists, one with unique elements, and one with repeating elements. I want to find whole occurrences of ...
Gilman asked 30/6, 2010 at 19:21

6

Solved

For reasons I completely disagree with but "The Powers (of Anti-Usability) That Be" continue to decree despite my objections, I have a sorting routine which does basic strcmp() compares to sort by ...
Sonjasonnet asked 15/6, 2010 at 21:18

5

C bothers me with its handling of strings. I have a pseudocode like this in my mind: char *data[20]; char *tmp; int i,j; for(i=0;i<20;i++) { tmp = data[i]; for(j=1;j<20;j++) { if(st...
Perfunctory asked 10/5, 2010 at 16:40

8

Solved

I made a function like this: bool IsSameString(char* p1, char* p2) { return 0 == strcmp(p1, p2); } The problem is that sometimes, by mistake, arguments are passed which are not strings (meanin...
Pumice asked 26/10, 2009 at 9:2

© 2022 - 2024 — McMap. All rights reserved.