C :: Searching Word Using Strcmp

Nov 15, 2014

I'm trying to write function that finds wheter the searched word exists or not. The compiler gives warning. Where is my wrong ?

|21|warning: passing argument 1 of 'strcmp' makes pointer from integer without a cast [enabled by default]|

Code:

#include <stdio.h>
#include <string.h>
int main ()
{
int result;
char arr[]="sakir emmim evde mi evde mi dedik lan";
int size=sizeof(arr)/sizeof(char);
char key[20];
scanf("%s", &key);

[Code]...

View 6 Replies


ADVERTISEMENT

C :: Comparing Password With Strcmp

Oct 7, 2013

I'm a novice with C programming and i have to solve an error in the following code. The code works like you enter a password called "uoc" and it shows as OK. But surprisely when you entered another password as "Cambridge" it works fine too.

I think that the problem is in the array declaration but i'm checking resources and no success!

Code:
#include <stdio.h>
#include <string.h>
struct {
char str[8];
char ok;
} data;

[Code] ......

View 3 Replies View Related

C :: Strcmp Of 2 Multidimensional Arrays

Aug 6, 2014

I have used strcmp before on one dimensional arrays but not 2 dimensional arrays.The problem is that I have one 2d array that has text with some misspelled words and I have to compare it to another 2d array and if the word from the first array (misspelled word) is not in the 2nd array then I print it to the screen instead of correcting the spelling. Here is what I have so far:

Code:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int read_dic(char [], char [][20]);
int read_words(char [], char [][20]);
void typo_check(char *, char *);
}

[code]...

View 5 Replies View Related

C :: Strcmp Return Value On Different Compilers

May 3, 2013

I'm having a problem with the strcmp return value. My compiler returns the correct value based on my research, but I tried to compile the code below on those online compilers and the result was 1.

My compiler gave me 10, which I consider to be the correct result according to strcmp - C++ Reference. So strcmp is not very portable?

Code:
#include <stdio.h>
#include <string.h>

int main(void) {
printf("Return value: %d
", strcmp("Rocks", "Rockie"));
return 0;
}

View 6 Replies View Related

C++ :: Comparing Two Strings With Strcmp

Jun 22, 2014

I have trouble comparing two strings with strcmp. The bold part of the code are the parts that are not working and i hope somebody can explain to me what i did wrong. Goal of the code is to compare a city name with the name of already created cities and when two of them match to creat a Street between them. Depending on the street pointer different streets can be created

my vector containing all already created cities (it seem to work)
std::vector<city*> citylist;//all cities

find city using strings and creating a road between them:

bool Map::add_street(Street *street, const string firsttown , const string secondtown) {
city* hilfs1=Map::find_city(erste);
city* hilfs2=Map::find_city( zweite);
if (hilfs1==NULL || hilfs2==NULL)
{return false ;} // Problem :both pointers are always NULL

[Code] ....

Here is also my implementation of the getname function :

std::string city::getname() {
return this->name;
}

View 2 Replies View Related

C :: Strcmp Negative Value From User Input

Jul 24, 2014

I am studying c and I thought what would be better than using my pi to play with relays and c. I am used to PHP as a scripting lang and don' t do much programming. So I wrote this to use wirepi and ask the user "on or off" they type on or off and it does it. it does work but I know something is wrong when I use strcmp in the if statment I can -10 for a value. Here is the code.....

Code:
#include <stdio.h>
#include <string.h>
main(int argc, const char * argv[]) {
char oo[100];
system("gpio mode 0 out");
printf("Do you want it on or off?

[Code] ....

This is what it outputs at the prompt

Do you want it on or off?
on
on

It is now on!

How can I just get Code: if (oo = on) {} and like so with off.

View 2 Replies View Related

C++ :: Seller Array - Error When Trying To Use Strcmp Function

May 1, 2014

I'm having an error when trying to use the strcmp function. Here's the jist of the code I'm working with:

Code:
class Seller
{
public:
Seller();
Seller( char [], char[], char [], double );

[Code] ....

I'm getting a
"[Error] cannot convert 'Seller::getID' from type 'char* (Seller:: )()' to type 'const char*'"
on this line of code:
"if (strcmp(sellerArray[i].getID, sellerArray[j].getID) < 0) "

How do i have this method able to compare these values in my seller array? Granted, there is more to the code and things actually in the seller array at this point. Is there something I'm not seeing??

View 4 Replies View Related

C++ :: Boost Binding - Comparing String Using Strcmp

Jun 5, 2014

I am trying to compare strings (char*) using strcmp but I am having a hard time doing it with boost::bind. It compiles but it crashes when I run it.

I have a std::vector<boost::shared_ptr<DeviceInfo>> cMonitoredDevices and one cCurrentDevices. I used a typedef DeviceContainer for std::vector<boost::shared_ptr<DeviceInfo>>.

DeviceInfo is a simply struct that contains a char[128] Name (and other fields not important for this issue) that I want to use to compare.

So I am trying to find the DeviceInfo (based on Name) that are in cMonitoredDevice but not in cCurrentDevices. My problem is retrieving the Name value for the strcmp. Here is what I have so far

for(DeviceContainer::iterator pDevice = m_cMonitoredDevices.begin();
pDevice != m_cMonitoredDevices.end(); pDevice++) {
if (std::find_if(cCurrentDevices.begin(), cCurrentDevices.end(),
boost::bind(&strcmp, boost::bind(&boost::shared_ptr<DeviceInfo>::value_type::Name, _1),
(*pDevice)->Name) == 0) == m_cMonitoredDevices.end()) {
}
}

View 2 Replies View Related

C :: Passing Arg 1 Of Strcmp Makes Pointer From Integer Without Cast

Jan 18, 2015

Code:

#include <stdio.h>
int main(){
int a=15 ;
int b =20 ;
strcmp((a, "20") == 0) {
printf("Correct!");

[Code] .....

passing arg 1 of `strcmp' makes pointer from integer without a cast

View 11 Replies View Related

C++ :: Strcmp Function - Comparing String Data From Two Different Files

Dec 20, 2013

I am having a slight issue with the strcmp function. I am comparing string data from two different files. I want the function to output a set of information if the strings are the same and a different set of data if the strings are different. My issue is, the function outputs the data that's the same but not different.

I had an else statement that compared the data if it was NOT equal but it only duplicated the data in the file.

One file is a listing of 100 books with 10 lines of information and an assigned market. The second file is a listing of the markets contained in the books file. However, the books file has a market that is not located in the markets file. The "missing" market is what is not priting or displaying.

// final project2 file

#include <iostream>
#include <string>
#include <iomanip>
#include <fstream>

using namespace std;
const int ARRAY_SIZE = 500;
const int MARKET_ARRAY = 6;
ifstream infile, infile2;
ofstream outfile;

[Code] .....

View 6 Replies View Related

C++ :: Strcmp On Linked List Data And String Constants?

Sep 28, 2013

why strcmp() doesn't return true when comparing a string constant with a string that was acquired via a linked list. By the way, the data in the linked list was taken from a text file. Does that imply that there's a new line () character in the string from the linked list?

Code:
struct Node{
char ACNO[15];
struct Node *next;

[Code]....

View 1 Replies View Related

C++ :: Hangman Definition Game - Extract Word Randomly Form File And User Guess The Word

Jun 25, 2014

Basically I have a text file called words. I'm supposed to extract a word randomly form the file and have the user guess the word. If they guess the word correctly in x number of tries they will receive the definition.

I'm having trouble receiving that random word and I'm getting the definitions from the file.

Here's my code:

#include <iostream>
#include <fstream>
#include <string>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
using namespace std;

[Code] ....

This is what is in the words.txt file
apple#the usually round, red or yellow, edible fruit of a small tree
boat#a vessel for transport by water
horse#a solid-hoofed plant-eating domesticated mammal with a flowing mane and tail, used for riding
television#a system for transmitting visual images and sound that are reproduced on screens
soup#a liquid dish, typically made by boiling meat, fish, or vegetables, etc.
bottle#a container, typically made of glass or plastic and with a narrow neck
barber#a person who cuts hair
toast#sliced bread browned on both sides by exposure to radiant heat
radar#a system for detecting the presence, direction, distance, and speed of aircraft, ships, and other objects
red#of a color at the end of the spectrum next to orange and opposite violet

View 3 Replies View Related

C :: Display Function Displays All Letters Of Word Entered Instead Of Word Itself

Feb 18, 2013

I am building a linked list and i need to display function i have. The display function displays all the letters of the word entered instead of the word itself. below is my struct, one of my functions and the display function.

Code:

//-----------struct ------------//
struct Node
{
char data;
struct Node *next;
}*Head;

[code]....

View 1 Replies View Related

C++ :: Program That Reads A Word From User And Then Print (cout) This Word

Oct 24, 2013

I'm learning programming, and C++. I've got a question, but I couldn't solve my problem so far. I need to use arrays and only basic stuff to solve this:

Create a program that reads a word from the user and then print (cout) this word on contrary. It's simple, I know, but I can't do it,. I've tried some stuff but I don't get how I will get the proper values to do this. All I know is that I can use variable.lenght().

View 7 Replies View Related

C/C++ :: Opening Word Document In Turbo Or Any Program In Word Format

Mar 20, 2013

I have a problem to open word document into turbo c++. i don't know how to open if the documents are in word format.

View 1 Replies View Related

C/C++ :: Convert 1st Letter Of Each Word To Uppercase And Then Display Only The Last Word?

Dec 27, 2013

I want a program to display as follows..

if i enter mohandas karamchand gandhi i want output as M K Gandhi.....

i want the c++ code for this program..my error is i am not able to erase the letters of first 2 words..ie my output is Mohandas Karamchand Gandhi..

View 2 Replies View Related

C++ :: Simple Word Counter - Show Repetition Of Word

Apr 25, 2012

I've taken part the text into 1 word per line, but I can't figure out how to printf every word only once and then add (%d) in the end to show how many repetitions of that word there are.

Code:
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
using namespace std;
int main(){
char *oneword;

[Code] ....

View 3 Replies View Related

C :: How To Find Word And Insert Another Word After That In Text

Dec 20, 2013

I have text (string) and I want to find a given word (it's ok!) and then insert another given word after the first word. The original string is beeing copied into a new string. But something is going wrong!!! Where is my mistake?

(I have some patches...)

Code:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
//insert "new_word" after each occurence of "word"
int main(){
char A[100]="In the sentence words the and the.";

[Code]...

View 8 Replies View Related

C++ :: Fstream Class Not Reading Word For Word

Aug 6, 2013

int countTextWords(ifstream * file)
{
string textWord;
int wordCount = 0;
while((*file) >> textWord)
{
wordCount++;
}
return wordCount;
}

for some reason, (*file) >> textWord will not read words into the string. What am I doing wrong?

View 9 Replies View Related

C++ :: Word By Word From A Line In File?

Aug 14, 2014

ow to read word by word from a line in file into struct. Say for example:

12345 Joe Lim KH879.00
12233 Kay Suet Yee35.98

to

struct master {
unsigned short int IDnum;
char name[30];
float salesCustomer;
};

View 1 Replies View Related

C :: Word By Word Search

Apr 25, 2013

i'm making a program for basic data entry.i have also included search feature which uses strcmpi() function.if i have a file name'report on tigers' and someone searched for 'tigers' then that person will not find the required file.any way i can overcome that ?

View 2 Replies View Related

C++ :: Searching By Last Name?

Oct 23, 2013

I have an assignment to create an address book in c++ where you can enter contact information and then search all entries via last name. I am trouble figuring out how to write a function that will be able to search an entry by last name. Here is my code so far:

#include <iostream>
using namespace::std;
class addBook {

[Code]....

View 1 Replies View Related

C++ :: Searching In CSV File?

Feb 6, 2013

My .csv file is like:

Bone,origin,deep/superficial,location, action.

with list of 38 bones.

This is my main.cpp:

#include <iostream>
#include <fstream>
#include <sstream>
#include <vector>
#include <cstdlib>
#include "Action.h"
#include "Action.cpp"

[Code] .....

For action, if user enters action, it will output the bones involved with that action.
For strengthening, if user enters location, it will output bones involved with that location.
For dagnostic, if user enters bone, it will output location of bone and whether bone is deep/superficial.

How I could search in csv file for these.

View 11 Replies View Related

C# :: Searching DB For Value In Textbox (WPF)

Nov 3, 2014

WPF window I'm working on. I have a window that has a textbox to enter a name to search a database table for, and when the search button is clicked, the ID for that username will be returned to a separate textbox. The code I've written atm doesn't seem to be working, but it looks fine to me. Here's what I've got;

private void btn_SearchUsers_Click(object sender, RoutedEventArgs e)
{
if (!string.IsNullOrWhiteSpace(txtb_SearchName.Text))
{
SqlConnection sqlCon = new SqlConnection(conStr);

[Code] .....

So, I have the value entered into the textbox to be searched for stored in a variable, I'm selecting the ID from the table when the name in the variable is found, storing the result in a DataTable, and then in my foreach loop, if I find the name (the name column being index 1 in the table), I set set the ID result textbox to equal the ID for that name (the ID column being index 0 in the table). I think the foreach part is what's throwing me off. Maybe the column stuff? My Users table is like;

ID Name
1 John
2 Roger
3 Mike

View 3 Replies View Related

C++ :: Functions Searching A Database

Aug 8, 2013

I am trying to write a program to search a library file with the name of a book or author and return the books that match the searched string in some way. For instance, if I search "Develop" it should display Game Development Essentials(Novak) and Developing Games in Java(Brackeen) and tell me that 2 records were found. Currently, it shows all the records regardless of what i search for, even if it is jibberish. Am I missing something in my functions? should I include the code that accesses these functions?

//If the user chooses A or a
int showBooksByAuthor (int count, string name)
{
char choice;
int index = 0;
}

[code]....

View 1 Replies View Related

C++ :: Searching For Line Intersections

Jul 26, 2013

I'm pretty decent at maths, and fair at programming but how I'd actually write mathematical line equations or check for intersections in script.

View 5 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved