DeanMSands3 69 Junior Poster

Look into cross-platform libraries.
I like SFML. Unfortunately version 2 isn't finished yet.
SDL has been around forever and a day. It has a nice community following.
There are others. Google is your friend.

Happy coding.

DeanMSands3 69 Junior Poster
  • Use "Product Activation"
  • Use a web-installer with a server that generates content encrypted for that machine only.
  • You don't.

Happy coding.

DeanMSands3 69 Junior Poster

This sounds suspiciously like the problem Gourav1 posted last week. I provided an answer that should satisfy.

See his post here:
http://www.daniweb.com/software-development/c/threads/407089/1737797#post1737797

See my response here:
http://www.daniweb.com/software-development/c/threads/407089/1738493#post1738493

Gourav1's question was directed at text animation. However, a graphical solution could easily be adapted.
When drawing your image, draw by columns, and offset each column by a rotating value in an array.

DeanMSands3 69 Junior Poster

Ah, right. I sometimes get mental dyslexia when I read something too fast (and subsequently jump into coding). Two ways to do this.

If you just want to get numbers 0 through 9 (or even 19), you can make an array of strings, and for-loop through them using strcmp. If strcmp gives you 0, you've got your match. Break out of the for-loop and return the number to the user or whoever wants it.

However...

If you want a full-fledged Text to Number, we need to do things differently. Let's start with the following even though it is wrong:

  1. setup a hash table of lower-case strings and their corresponding integers.
  2. convert the string to lower-case
  3. read through the string past any initial white space to the actual word and up to the next non-letter (presumably white space)
  4. hash the word
  5. find the hash in a mapped table and get the associated integer.

This will handle numbers 0 from 19. It will even handle the individual multiples of ten (twenty, thirty, forty, etc...). But it won't handle larger numbers. Why not?
We're only working with one word.

Looping and multiplying by 10 won't work either.
To get 123 we'd have to say "one two three" instead of "one hundred twenty three".

Before I go to far, I presumed I'd have to section out the sub-thousand numbers into their own little word before adding them to some sort of accumulator. I even …

DeanMSands3 69 Junior Poster

Look at this function from the site I mentioned earlier. I did some debugging and the mouse coordinates start way out in never never land even though the cursor is clearly visible on the screen. Restrict the mouse coordinates to the display min and max and you're good. Look into getmaxx() and getmaxy() on getting those.

void restrict (int x1,int y1,int x2, int y2)
{
	in.x.ax = 7;
	in.x.cx = x1;
	in.x.dx = x2;
	int86 (0X33,&in,&out);
	in.x.ax = 8;
	in.x.cx = y1;
	in.x.dx = y2;
	int86 (0X33,&in,&out);
}
DeanMSands3 69 Junior Poster
char numberAsString[6];
char numbers[][]=
{"Zero","One","Two","Three","Four","Five","Six","Seven","Eight","Nine"};
do{
    printf("Enter a number (0-9): ");
    scanf("%d",&number);
}while(number<0||number>9);
strcpy(numberAsString, numbers[number]);
printf("You entered %s.\n", numberAsString);
WaltP commented: How does this convert TEXT to a NUMBER? -4
domatessuyu commented: don't work +0
DeanMSands3 69 Junior Poster

Gourav1, you are now my new favorite poster. You give us problems from 15 years ago. To check and debug your code, we'd need DOSBox and an ancient (and completely legitimately obtained) copy of Turbo C++ 4.5. Epic win.

http://www.go4expert.com/forums/showthread.php?t=21153

Have a look at this page. Run all the examples. And see what works.
I'm wondering if perhaps your mouse coordinates are outside the drawing range of the screen. Who knows?

DeanMSands3 69 Junior Poster
DeanMSands3 69 Junior Poster
DeanMSands3 69 Junior Poster

As promised:

#include <windows.h>
#include <stdio.h>
#include <stdlib.h>

struct sThread{
	LPSECURITY_ATTRIBUTES attr;
	SIZE_T stack;
	LPTHREAD_START_ROUTINE function;
	LPVOID params;
	DWORD flags;
	DWORD id;
	HANDLE handle;
};
typedef struct sThread thread;
struct sAnswer{
	long Number;
};
typedef struct sAnswer answer;

void fromMagratheaWithLove(void *ptr2Answer)
{
	DWORD ptrAsDWORD;
	answer *earth=((answer*)ptr2Answer);
	earth->Number=42;
	ptrAsDWORD=(DWORD)earth;	//Oh yes, I did.
	ExitThread(ptrAsDWORD);
}

thread *lazyThreadConstructor(void (*function)(void*), void *params){
	thread *t=(thread*)malloc(sizeof(thread));
	t->attr=NULL;
	t->stack=0;
	t->function=(LPTHREAD_START_ROUTINE)function;
	t->params=(LPVOID)params;
	t->flags=0;
	t->id=0;
	t->handle=0;
	return t;
}
HANDLE lazyThreadStarter(thread *t){
	t->handle=CreateThread(t->attr,t->stack,t->function,t->params,t->flags,&t->id);
	return t->handle;
}
void lazyThreadDestructor(thread *t){
	t->attr=NULL;
	t->stack=0;
	t->function=NULL;
	t->params=NULL;
	t->flags=0;
	t->id=0;
	t->handle=0;
	free(t);
	t=NULL;
}
int main(int argumentCount,char *arguments[]){
	thread *t;
	answer *toLifeTheUniverseAndEverything;
	answer dontTrustTheMice;
	DWORD slartibartfast;
	t=lazyThreadConstructor(fromMagratheaWithLove, &dontTrustTheMice);
	t->handle=lazyThreadStarter(t);

	WaitForSingleObject( t->handle, INFINITE );
	GetExitCodeThread(t->handle,&slartibartfast);
	toLifeTheUniverseAndEverything=(answer*)slartibartfast;
	printf("The answer to life, the universe, and everything is %ld\n",toLifeTheUniverseAndEverything->Number);
	printf("This tutorial should not be taken seriously.\n");
	CloseHandle(t->handle);
	lazyThreadDestructor(t);
	return 0;
}
vedro-compota commented: ++++++ +3
DeanMSands3 69 Junior Poster

Thanks for the responses guys. I'm going to try to learn both JWASM and GNU Assembler.

DeanMSands3 69 Junior Poster

How many copies of MinGW do you have on your system? If you're using Dev C++, then that makes at least one.
Reference: http://cboard.cprogramming.com/cplusplus-programming/111216-compiler-problem.html

Make sure to use a recent copy of MinGW and update often. I would also include a bare-minimum MSYS including Make.

DeanMSands3 69 Junior Poster

Let's view this a little differently with the offsets at the top:

2|1|0|0|1|2|3|3
===============
 | |1|1| | | | 
 |1|2|2|1| | | 
1|2|3|3|2|1| | 
2|3|4|4|3|2|1|1
3|4|5|5|4|3|2|2
4|5| | |5|4|3|3
5| | | | |5|4|4
 | | | | | |5|5

So for this particular array, we would use an offset array of 2,1,0,0,1,2,3,3. The array has a length of 8.
The offset array repeats smoothly. That means we can leave the end of the offset array and start back from the beginning.
Your main loop could take the following form:

WHILE NOT KEYPRESS
    ClearScreen
    FOR I EQUALS 0 TO NumberOfColumns
       PrintColumn I with Offset = I + OffsetArray[OffsetIndex]
    Increment OffsetIndex By 1
    SET OffsetIndex = OffsetIndex MODULUS LengthOf(OffsetArray)
WEND

But all is not done. In addition to a character array, you need a color array. You can however cheat and simply use spaces instead of characters. This way, you'd only need a color array to set the background color and print a space for each "pixel" in the flag.

Let us know if you need further help.

DeanMSands3 69 Junior Poster

Let's start with the basics.

You're going to print out a set of characters in an array on a screen.
You're going to jiggle the characters by a wavy function, let's say the sine function.
You're going to output in color. Each character in the array has a color assigned to it.
You will have to clear the screen or erase or write over every character so you don't have garbage left over when you do a drawing pass.
You're going to want to use a while loop that breaks on key press, but also increments a value that controls what vertical offset will be used.


Let's say we have a character array:

11111111
22222222
33333333
44444444
55555555

and we want it to look like

11   
 1221  
123321
23443211
34554322
45  5433
5    544
      55

(to be continued...)

DeanMSands3 69 Junior Poster

http://comsci.liu.edu/~murali/win32/ExitCodes.htm
Check the second to last example. I'll post another in a bit.

DeanMSands3 69 Junior Poster

Threads can return values.

Which API are you using?
Here's an example for PThreads:
https://computing.llnl.gov/tutorials/pthreads/#Joining
Since the thread function is a void pointer, it can point to any piece of data you like, and is retrievable with the pthread_join function.

For Windows, you can use the GetExitCodeThread function.
http://msdn.microsoft.com/en-us/library/windows/desktop/ms683190(v=vs.85).aspx

vedro-compota commented: +++++++++ +3
DeanMSands3 69 Junior Poster

I haven't gotten into CLR C++ yet, but I'll take my best shot.

MyDataType_Class ^myFunction(String someName="",int someID=0){
    MyDataType_Class ^new Person=gcnew MyDataType_Class();
    Person->id=someID * 2; //Multiply by 2 just because
    Person->name=someName;
    return Person;
}

.
.
.


void SomeOtherFunction(){
    MyDataType_Class ^thisPerson=myFunction("Runcible Spoon", 21);
.
.
.
}
DeanMSands3 69 Junior Poster

OK, let's back up and explain a few things.
When you create an array with, let's say, char x[]="I'm an array!"; C sees this as an array of characters.
Now let's look at this example: char y[]={'I',' ','a', 'm', ' ', 't', 'o', 'o', '!', 0}; //Note the trailing 0. That signals the end of the string.
Both are arrays of characters. And they are single-dimensional.
Let's look at this. char z[][]={"I'm ", "an ", "array ", "of ", "arrays!"};
This is a two dimensional array. Notice that there are two []'s behind the z.

Let's go back to your code.

You have multidimensional arrays instead of single dimension arrays. You should change your array initialization from char j[]= to either char j[][]= or char *j[]=.
Also, you have trailing commas in your {}'s. Do a search for ,}; and change it to };
The compiler may see the commas and be expecting more data. Or not. Different compilers are different.
You'll be all set.

DeanMSands3 69 Junior Poster

One thing, take out the cos= in the show_all function.

cos=scanf("%d",cos);
//Should be
scanf("%d",cos);
DeanMSands3 69 Junior Poster

@WaltP: Those are very good points, and I agree.
@Yamna Midhat: OK, some things I see after some minor debugging.
Line 105: Missing ampersand. Change that to

scanf("%d",&cos);

Line 336: Missing ampersand. Change that to

scanf("%d",&item_no);

At delet_selectd(): you're not checking current->next to see if it's allocated yet. This will save you some grief.

DeanMSands3 69 Junior Poster

I can think of two ways to do this. (Also, get rid of the return j. It returns from the main function and exits the program. Get rid of the printf(j) at the bottom. Why do you have it?)

First: using arrays.
Since you're using characters 7 lines tall, create 7 arrays each about 80 bytes wide. Actually, I would take the width of your longest character (about 5), add 1 for a space (5+1=6), multiply by 3 since you have 3 characters (6*3=18), and add 1 for a trailing 0 (18+1=19). So you could create 7 arrays of 19 characters. Or a 7x19 matrix. Then, instead of doing printf for every character, use strcat. THEN, when you're finished strcat-ing all your characters together, do a printf for each array.

Second. Use a console cursor moving function. If you're using Windows, check out http://www.daniweb.com/software-development/cpp/threads/22498

Otherwise, in Linux (which lets you use ANSI), use something like this:

char escape=27; int y= 1;int x=7; 
//{1,7} will park you at the upper left corner of the second character
printf("%c[%d;%dH",escape,y,x);
DeanMSands3 69 Junior Poster

In my wayward youth, I learned a little bit of inline assembler in Turbo C. And that was fun. Then I got into DJGPP which came with GCC and Bell Syntax. And it was confusing. And I gave up.

Fast forward 12 years. I'm 30, finishing a bachelor's in CS. I've had two classes in MIPS Assembly. I self-taught myself PIC assembler. And I'm willing to give Intel assembler a second chance. And I'm interested in both Windows and Linux assembler.

Which ASM do I learn?

NASM seems the most user-friendly and familiar. It compiles just fine with my GCC programs. And it's cross-platform. I really want that.
GAS uses Bell Syntax. I've heard that once you go Bell, you never go back. Once you get over the learning curve, you love it. At least, that's what I've been told. And it's cross-platform.
MASM comes with lots of fun macros. It seems like one I can get a job with. Not cross-platform.
FASM is something I've heard good things of, but really know nothing about.

Help me out, DaniWeb. Where do I go?

DeanMSands3 69 Junior Poster

Wait for the screen to refresh. See if your API will let you do that. What API are you using anyway?

DeanMSands3 69 Junior Poster

try is a keyword. Also, have you already allocated the memory space for character array pointed to by *filename? (By allocate, I mean like char buffer[20];myFilename=(char*)buffer;try(myFilename); or myFilename=new char[20];try(myFilename);

DeanMSands3 69 Junior Poster

So... I thought, how would I do this the RIGHT way in C? No STL at all. Hm...
Arrays, well, they're kind of passe'. Linked Lists are the bees knees. Or something. I was thinking about using BSTs, but wasn't sure at what point to implement leveling/balancing. I decided that would be for the next little project.
BTW, if this code is shoddy, I apologize. I wrote it from scratch. I'm still in college, so cut me a little slack.

//============================================================================
// Name        : TextAnalyzer.c
// Author      : Dean M. Sands, III
// Version     : 0.7e (I made that number up.)
// Copyright   : I will set fire to the flamingos, if any, in your front yard.
// Description : Linked List Experiment in C.
//============================================================================

#include <string.h>	//for malloc
#include <ctype.h>	//isalpha
#include <stdio.h>	//File functions
#include <stdlib.h>	//free

/******************************************************************************\
*                           Generic Functions                                  *
\******************************************************************************/
long hashBlock(char *pointer,long length){
	long i;
	long hash=0;
	//Same hash function as Java String
	for(i=0;i<length;i++){
		hash=(hash<<5)-hash;	//Multiply by 31
		hash+=(long)pointer[i];
	}
	return hash;
}

long	getFileSize(FILE *myFile){
	long fileSize;
	fseek (myFile, 0 , SEEK_END);
	fileSize = ftell (myFile);
	rewind (myFile);
	return fileSize;
}

/******************************************************************************\
*                           Buffer  Functions                                  *
\******************************************************************************/
//I'm not even sure why I created this data structure. It seemed like a good idea at the time.
typedef struct {
	char *data;
	unsigned long length;
} buffer;

//Destructor
void destroyBuffer(void *deadBuffer){
	buffer *myBuffer=(buffer*)deadBuffer;	//Why not directly? So I can use in destroyLinkedList.
	//If already freed, return.
	if(myBuffer==NULL)
		return;
	//Is data …