Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

you will probably want to truncate all trailing spaces first before using Narue's solution. Otherwise it will not work if the line is like this

"1 John US 1234.00          "
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Ah i see I was getting confused I thought it pointed to the first instance of james smith and not the start of the line so if there was something in the string before james smith for example "his name was james smith" it wouldn't be the start of the line.

That's the purpose of if( ptr == line) -- to see if ptr starts at the beginning of the line or somewhere in the middle, as in your example. But in the string "his name was mrjames smith", the check *(ptr-1) == ' ' will not be true because the character just befor the 'j' in 'james' is 'r', not a space.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

start at the beginning, not somewhere in the middle of things.Here is a good tutorial to get you started.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Hi I have just two questions about the code below when using char *ptr = strstr(line,"james smith "); does this mean that the if statement:
if( ptr == line || isspace(*(ptr-1))) is no longer needed?

what about the string "mrjames smith" ? will you accept a pointer to that too? If not, then that code is still needed.

I was also wondering is the comment is correct in saying if ptr is at the beginning of the line because doesn't ptr just return a pointer to the first place it finds james smith, so how could it know if it is at the beginning of the line or not?

not certain what you are asking, but if ptr == line, then ptr is pointing to the first character in line. This is testing the address of ptr and line, not comparing the two strings.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>Is there any way... tht as soon as the mspaint is opened my next instructions will start working...

Yes, use win32 api function CreateProcess() see MSDN for parameters and details. The description in MSDN may look a little overwhelming, but most of the parameters are 0.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

lets say that instead of typing just y + '\n', you type a whole bunch of keys then '\n' at the end. fgets() will only grab from the keyboard buffer the number of keys that will fit in the buffer (sizeof the buffer - 1 for null terminator), the remaining keys will stay in the keyboard buffer until your program removes them. And the buffer returned by fgets() will contain '\n' only if there is one in the input stream.

The loop that dwks posted is probably the savest way to flush out (empty) the keyboard buffer that contains an unknown number of characters.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

how do you want to store the data -- or do you want to type evetything in each time you run the program?

Use a loop so that you can enter more than one name/address pair during the same instance of the program.

after asking for Eric's address, use a variable and cin to get the address from the keyboard.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I don't know how you posted that code, but you should have use simple code tags. Please edit your post to use code tags.
[ code ]
// code goes here
[ /code ]

just remove the spaces between the square brackets.

unless you are using a very very old c++ compiler such as turbo c++ you should be using <iostream> not <iostream.h>. And you don't need conio.h at all. replace getchar() with cin.get().

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

use getchar() after each numeric input using scanf(). you need it in two places in your program.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

when you press 'y' followed by <Enter> key, there are two keys in the keyboard buffer -- so the second time through the code it is probably getting the '\n' key. you need to flush the keyboard buffer to remove the '\n'.

scanf("%c", &yorn);
getchar(); //flush the keyboard buffer of the '\n' key

or you could use fgets() which will flush the '\n' too assuming the user types on 'y' followed by <Enter>. If anything else is typed then those keys will also be in the keyboard buffer. There is no easy standard solution to the problem. Make the buffer in the code below big enough and fgets() will probably be able to fill it with all the keys in the buffer.

char buf[3];
fgets(buf,sizeof(buf),stdin);
yorn = buf[0];
jhdobbins commented: solved problems with no trouble :) +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

How To Find Max Of 3 Numbers Without Using Comparison Operators?

Is that the exact and whole problem? Or did you paraphrase the problem? I don't believe there is a solution to the problem you posted if none of the solutions previously posted are not acceptable. If there is, I hope someone posts it :eek:

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

yeah i had wrote it myself,

Good -- just checking because the question you asked makes one believe otherwise.

just because i am kinda a rooky

We've all been there, done that.

dis my work... ='(

I have no idea what that means. :eek:

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

did you really write that program? or did you just copy it from somebody else? Look closely and you will see that it is printing the same thing over, and over and over one each iteration. But of course you already know that if you had written it youself :rolleyes:

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

its C++ .

No it is NOT c++. The code you posed is probably run through another language's preprocessor which translates it into c++ code. You cannot compile that code directly with a c++ compiler. It must be interpreted by anothr preprocessor first.

Many database 4GL programs are like that. The code is similar to c an c++, but isn't.

>>C1004
you can get that error several ways. mismatches braces, brackets #ifdef/#endif are a few. It can be a real bear sometimes to find the error. One of my debugging solutions to find it is to start commenting out large blocks of code until I find the problem.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
set $@array_size, getarraysize(getarg(0));

That is neither a standard C or C++ statement. You will have to find out what language it was written in, then learn what it does. my guess is that it is assigning the return value of function getarraysize() to variable $@array_size

int array_size = getarraysize(getarg(0));

now I have no clue what getarg(0) will return. you will need to find that out too.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

<<'line vb will do'

typo -- replace "line" with "like".

You do know how to write c/c++ programs don't you?

I don't think it will be very easy to port that code. What are you trying to do anyway? Why port it at all? there is a huge amount of code examples to follow if you want to access a database in c or c++. There are even some c++ classes on the net.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

does it work the way it is intended? If yes, then why fix something that ain't broken? But its obvous that it doesn't do what you want it to do.

What kind of database are you supposed to use? MySql, MS-Access, simple flat-text file? or something else?

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I just tried it -- macors won't work either because the compiler doesn't like the '@' character. You will have to resort to brute force and manually make all the changes. For example, change $@db_count to db_count. you also will have to declare the data types because c will not let you use a variable before it is defined, line vb will do.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

like I said before, you wil be spinning your wheels because you are attempting to compile a program that isn't c or c++. you might also make macros out of those funny-looking variable names to redefine then according to c and c++ rules.

#ifndef function

do you have a matching #endif for that???

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

menu Project --> Settings, select the c++ tab, select Category of Precompiled Headers then select the radio button Not using precompiled headers

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

the source was not written in either c or c++, maybe in basic of java. you will have to do a complete rewrite (port) if you want to use a c or c++ compiler. And the answer to your question is No -- simply declaring the function will not fix the errors.

[edit]
>>How can I fix this?

put at the very top of the program

#include "stdafx.h"
.. // rest of code here

or remove precompiled header requireents.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

It is for a group of source files which is why some things dont make sense.
The errors I'm getting are:

F:\Mike\eAAC Test Part I.cpp(4) : error C2146: syntax error : missing ';' before identifier 'script'
F:\Mike\eAAC Test Part I.cpp(4) : error C2501: 'function' : missing storage-class or type specifiers
F:\Mike\eAAC Test Part I.cpp(4) : fatal error C1004: unexpected end of file found

Just general errors it's found.

Yup ! just as I already told you, the compiler has no clude what function keyword is. It ain't c or c++.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

'Script' is an external function being called.
Its just general errors it contains, thats what I need help identifying..

not according to the code you posted -- its just so much garbage.

[edit]A closer look shows that the code you posted is neither C or C++, maybe pascal or some other language.

$@db_count

The above is not a C or C++ variable construction.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

there is no such thing (keywords) as function script in either c or c++. maybe in managed c++ (I don't know managed c++), but VC++ 6.0 compiler doesn't know how to compile managed code.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

[deleted]

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

the this pointer is not a pointer to an array but a pointer to a specific instance of the entire class. you are mis-using the this pointer. You need to post more code in order for anyone to show you how to do whatever it is you want to do.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

erase the window -- get current window RECT object then call FillRect() with the desired color.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

in c++ create a vector<int>, sort it, then print the 3d number. Otherwise I have no clue how to do it without comparison operator.

vector<int> array;
array.resize(3);
// populate the array with 3 random values
array[0] = rand();
array[1] = rand();
array[3] = rand();
// sort
sort(array.begin(),array.end());
// display the largest number
cout << array[2] << endl;
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

**this is an illegal dereference of the "this" pointer in c++. What is the intent of that assignment?

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

use braces to encose blocks of code. The below may or may not be what you intended.

for(int d=0; d<DEPTH; d++)
{
		for(int r=0; r<ROW; r++)
                {
			array[d][r] = **this
			for(int c=0; c<COL; c++)
                        {
				array[d][r][c] = cells.array[d][r][c];
                         }
			return *this;
                }
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

return (x*(1 + (k*n)/(1 + (k*x))));


that is not inside any function.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

since this is a c++ program, use std::string instead of char arrays. std::string is a lot easier to use.

struct Node
{
        std::string Descrip;
        double Price;
        int Quant;
        Node *Link;
};

...
void InsertFunction(char *InitDescrip, double InitPrice, int InitQuant, Node *Current)
{
        Current->Descrip  = InitDescrip; 
        Current->Price = InitPrice;
        Current->Quant = InitQuant;
        Current->Link = Root;
}

of course if you must use those C char arrays, then do this

strcpy(Current->Descrip,InitDescrip);
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

different calling conentions are needed for mixed languge programs -- mixing C, Pascal, Basic etc in one program.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

boost may have one. search that link for the word intersect and see how it is used.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I might do it like this at the end of main() it will write the file, but not read it. You will have to figure out whether you want to read the file back in at the beginning of main() or enter all the data as you do now from the keyboard. It makes little or no sense to do both.

int main(void)
{
finalgrade Students[20];
//int StudentCount = 0;
finalgrade::numStudents = 0;
int iNo;
do{
cout<<"Enter No of Students between(0 to 20): Enter 0 to Exit: ";
cin>>iNo;
}while (!(iNo >= 0 && iNo <= 20));
for(int j=0; j<iNo; j++)
{
Students[j].ReadRecord();
}
if(finalgrade::numStudents > 0)
cout << "Sr.No\tFirst Name\tLast Name\tExam #1 Grade\tExam #2 Grade\tHomework Average\tFinal Grade\tGrade\n";
for(int j=0; j<finalgrade::numStudents; j++)
{
Students[j].CalculateGrade();
cout<<j+1 << "\t";
Students[j].WriteRecord();
cout<<"\n";


ofstream (out,"datafile.dat",ios::binary);
if(out.is_open())
{
    out.write((char*)Students,sizeof(Students));
    out.close();
}

   return 0;
}

[edit]
your function WriteToDisk is wrong --
1. this is a c++ program so use c++ fstreams, not C FILE.

2. The function opens the file for read but you are attempting to write to it. Can't do that.

3. If you want to retain function WriteToDisk() then ignore the code I added in RED above.

4. fputs() writes '\n' at the end of the string -- I don't think that is what you want to do.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

what errors does your compiler produce? post the first few error messages.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>Where in the Main do I put this? Before or After:

put it somewhere then test your program to see if it works the way you want it to. Trial-and-error is part of learning to program.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>> almsot forgot on how to code in C or C++

you need to refresh your memory before continuing or you will get nowhere very fast. Dig out those old text books you bought (you DID keep them didn't you?) and do a few of the end-of-chapter examples.

I have no clue about hamming codes -- never used them, so I'm not any help at all.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

since finalgrade class does not use any c++ std containers such as std::string you can write the entire class in one statement. put this in main()

ofstream out("file.dat", ios::binary);
   if( out.is_open())
   {
      out.write(Students,sizeof(Students));
      out.close();
   }
}

and to read it back is just as simple

ifstream in("file.dat", ios::binary);
   if( in,is_open())
   {
      in.read(Students,sizeof(Students));
      in.close();
   }
}

The above is simple and quick. The problem with it is that you can't change the size of Students after the file has been written unless you add some additional info about how many student records are in the file then read only that many records.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Thanks I have got it sorted but I was just wondering what the following part of the code does:

if(ch && ch == string

thanks again

remove the "ch &&" -- its reduncent and not needed. That just checks to see that ch != NULL, but it can't be NULL when it reaches the if satement due to the line above it.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>Did I not do this correctly?

what did your compiler say about it? (you forgot to put a semicolon at the end of the while statement. ) You might also add an error message inside the loop so that you don't wounder by the program won't accept the keyboard input.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>the only difference between the code I tested and the code you have is that I started the array after the first brace and the array data was obtained from a text file so it was:


No it isn't. Check the loop very carefully -- the if statement is larger and there is a while statement you do not have.

repost your current program.

>>or does it matter that some parameters may have whitespace after the comma and some don't?

That should not be a problem because the if statement is checking for both conditions.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Well, without reading any further, delete those goto's!! Your instructor will probably remove credit for using goto. use while() or do - while() instead.

and please surround code with [ code ] and [ /code ] (remove spaces between brackets. That will make your code easier for others (and me) to read.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

what do you mean "convert it over" ? from what to what? What problems are you having? you need a more detailed description of your problem(s)

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

what doesn't "work promperly" ? compiler errors? runtime errors? if yes, post them.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Can you give me any advice acient dragon?

Yes, learn to read and comprehend what you read. I posted working code for you. Compare it with what you have to see what you are doing wrong.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

see if this helps.

#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>

int getCount(char* string,char* dataType)
{
	int counter = 0;
	char* ch = string;
	while((ch = strstr( ch, dataType)) != 0)
	{
							
		if( ch && ch == string || isspace (*(ch-1)) || *(ch-1) == ','|| *(ch-1) == '(')
		{
			counter++;
			// bypass everything up to the next space
			while(!isspace(*ch))
				ch++;								 
		}						
		else
		{						
			break;
		}
	}
	return counter;
}

int main(int argc, char* argv[])
{
	char str[] = "int foo(int f, int k, char u,int f, int a, char h)";
	int intCount;
	int charCount;
	intCount = getCount(str,"int ");
	charCount = getCount(str,"char ");
	
	printf("intCount: %d charCount: %d\n",intCount,charCount);
	return 0;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>it is at the start or previous character is whitespace but i also need the or comma clause.


just add more || operators on that line!

if( ch == temp || isspace (*(ch-1)) || *(ch-1) == ',')

or you could use a switch statement

switch(*(ch-1))
{
  case ' ':
  case '\t':
  case ',':
   // blabla
   break;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

why do you think it is incorrect? Is the char count supposed to include spaces and periods? How about end-of-line terminating characters?

Why not consider question mark ? and exclaimation point! as end-of-sentence terminators/

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Where can I see that this is correct AD?

On my setup (default as installed), there is a combo box located immediately below the menu bar that lets you select either Debug or Release. Not sure how to get to it via the menus. If you have Release mode set then you will get the problems you are experiencing.