nezachem 616 Practically a Posting Shark

Hey how do I make so this would save myfile as a text file?

pFile = fopen (("%s",filename), "w");

I tried to add .txt after %s but that doesn't help.

Let me guess: you are a Pythonian, right?
In C, ("%s",filename) is a comma expression; it evaluates to whatever is mentioned last, that is to filename . Now, if you need a "myfile.txt" file, why don't you just spell it out explicitly:

char filename[256] = "myfile.txt";
nezachem 616 Practically a Posting Shark

Ok so you need two functions that both accept the 2 dimensional array.

Why?

One function will update the "row" count and call the second function, which searches ONLY the specified row, but ALL columns in that row. The second function either returns the desired value or returns some kind of value indicating "value not found"

find2d does need to accept a 2d array. Then it passes one row at a time down to find1d. Am I missing something?

nezachem 616 Practically a Posting Shark
the client and the server already exist so i need a go between.

Then use select()

nezachem 616 Practically a Posting Shark

A segfault (or access violation) to begin with.
What is important is that if the program invokes an undefined behaviour, you may turn the logical thinking off. Everything becomes possible.

nezachem 616 Practically a Posting Shark

I understand the reason. Still it doesn't justify violating the rules.

nezachem 616 Practically a Posting Shark

It is a very nice disclaimer. The only problem (at least in US, and I suppose in UK as well) is that it has never been tried in a court of law. Until then nobody knows if it holds water.

nezachem 616 Practically a Posting Shark

This

int index = 0;
             while (strcmp(prog[index - 1], "-1") && index < NUM_PROG && cin >> prog[index++]);

looks really suspicious. At the first iteration you access prog[-1] , which invokes an UB. Not sure if it is a "real" reason.

nezachem 616 Practically a Posting Shark

At the moment I wrote that post I didn't see your code. You do not need to add brackets, that has been taken care of by operator new .

nezachem 616 Practically a Posting Shark

You probably have a

unsigned char buffer[BUFSIZE];

filled up with data. The condition you are looking for is that for a certain index i the datum in the buffer is 0xfd, and the datum at i + 4 is 0x06. This literally translates into

if((buffer[i] == 0xfd) && (buffer[i+4] == 0x06))

Apply this in a loop over the buffer (taking proper care near the end), and you are all set.

nezachem 616 Practically a Posting Shark
execlp(APP_PATH, APP_PATH, "some value");

Don't forget to null-terminate the arglist:

execlp(APP_PATH, APP_PATH, "some value", 0);
nezachem 616 Practically a Posting Shark

This is definitely a wrong venue. You need to ask lawyers in your jurisdiction, not programmers all over the world.

According to my belief system, in the afterlife a keylogger writer will share a cubicle with a spam operator and a product manager.

sknake commented: agreed +0
nezachem 616 Practically a Posting Shark

PIL does not support alpha in BMP files. You need to strip it yourself. Something like (warning: untested):

img = Image.open("file.png")
r, g, b, a = img.split()
img = Image.merge("RGB", (r, g, b))
img.save("file.bmp")
nezachem 616 Practically a Posting Shark

Sin(x) = x - x^3/3! + x^5/5! + x^7/7! ...

Just wondering: are you intentionally trying to mislead OP?

nezachem 616 Practically a Posting Shark

So, what have you done so far? Do you need help with the algorithm or with coding?

nezachem 616 Practically a Posting Shark
afile >> stu[i].st.uks.name[MAX1];

This line (and similar lines in your code) doesn't do what you want. name[i] is a single character, not a string. Besides that, what does name[MAX1] refer to?

How to refer back to infile.txt, first column?

Hint: you just read it into n You are very close to a working file reading part.

nezachem 616 Practically a Posting Shark

It doesn't look like 8 bit. It looks more like 33 bit.

>>> int("100010101001000010000011111001010", 2)
4649453514

What result do you want?

nezachem 616 Practically a Posting Shark

One more bit of criticism.
YenToGb and GbToYen are practically identical. The only difference is that in one of them a value is multiplied by a factor, while in another it is divided by same factor. When you discovered that something is wrong (for example, a conversion factor changes), you'd have to fix a problem in two places. In programming such situation is called "double maintenance", and should be avoided by all means.
A standard solution is to get rid of one of them, and pass a factor as a parameter:

double convert_currency(factor)
{
    double in, out;
    ....
    std::cin >> in;
    out = in * factor;
    ....
}

and call it as

double factor = 149.2724;
    ....
    convert_currency(factor); // Pounds to yen
    ....
    convert_currency(1.0 / factor); // Yen to pounds

Next, your conversion function does too much. Besides actual conversion, it asks for continuation. It means that the function "knows" in what environment it is called. This is also considered a bad programming practice. Leave the controlling actions for the control loop.

As for your question, you declared your functions as returning int, while they actually return double. So just declare them as double.

nezachem 616 Practically a Posting Shark

Works for me

Well, this is, how shall I put it, cheating. Watch my fingers:

nezachem@home ~/tmp/dani/salem $ cat main.c
int main() { a1(); return 0; }

nezachem@home ~/tmp/dani/salem $ cat a1.c
extern void b2(void);
void a1(void) { b2(); }

nezachem@home ~/tmp/dani/salem $ cat a2.c
extern void b1(void);
void a2(void) { b1(); }

nezachem@home ~/tmp/dani/salem $ cat b1.c
extern void a2(void);
void b1(void) { a2(); }

nezachem@home ~/tmp/dani/salem $ cat b2.c
extern void a2(void);
void b2(void) { a2(); }

nezachem@home ~/tmp/dani/salem $ gcc -c *.c
nezachem@home ~/tmp/dani/salem $ ar cr liba.a a*.o
nezachem@home ~/tmp/dani/salem $ ar cr libb.a b*.o
nezachem@home ~/tmp/dani/salem $ gcc -g main.o -L. -la -lb
./libb.a(b2.o): In function `b2':
b2.c:(.text+0x7): undefined reference to `a2'
collect2: ld returned 1 exit status
nezachem@home ~/tmp/dani/salem $ gcc -g main.o -L. -la -lb -la
./liba.a(a2.o): In function `a2':
a2.c:(.text+0x7): undefined reference to `b1'  
collect2: ld returned 1 exit status  
nezachem@home ~/tmp/dani/salem $ gcc -g main.o -L. -la -lb -la -lb
nezachem@home ~/tmp/dani/salem $

What is the difference? The linker pulls a complete object file from the library, and does it on demand. In your example each library has just one file; that's why your command line worked for you - your libraries has just one object apiece. In a more typical case, the libraries have much more:

nezachem@home ~/tmp/dani/salem $ nm liba.a

a1.o:
00000000 T a1
         U b2

a2.o:
00000000 T a2
         U b1
nezachem@home ~/tmp/dani/salem $ nm libb.a

b1.o:
         U a2
00000000 T b1

b2.o:
         U a2
00000000 …
nezachem 616 Practically a Posting Shark

grep doesn't look for words. It looks for regular expression matches. You need to build a regular expression which matches either "apple" or "orange". For example, grep 'apple\|orange' . Different versions of grep have slightly different regexp syntax; read your manpage, and just play with them a little.

nezachem 616 Practically a Posting Shark

It's complicated only because you complicate things. For a task you stated, a simple loop

while(fread(s, ...) != 0)
    fwrite(s, ...);

suffices.
Can you explain how did you come up with the code you posted?

nezachem 616 Practically a Posting Shark

You have a number of problems here.

1. EOF is a constant, it is equal to -1. It never changes. If you what to know when you hit end of file, watch for the value returned by fread(). It will become 0.

2. Your "j" loop is really strange. Do you realize that you have a chance to write outside of tab1?

3. At line 21 fread modifies the value of "i'", which is also a loop counter.

4. I see other problematic places, but I will not comment on them, since I do not understand what you are trying to do.

nezachem 616 Practically a Posting Shark

I don't think that this implementation can be radically optimized. The Wiki article gives some advices on the speedup (Fourier transforms and image pyramid). Try them.
I'd expect that convolution will yield the best results, however it implies a very good math background. A pyramid could be a fun to program.

nezachem 616 Practically a Posting Shark

First of all, it's not end1 (with number 1) but endl (with a letter ell), short for endline.
Second, I really doubt that "Teach Yourself C++ in 21 Days" will do you any good.

tux4life commented: Exactly. +6
nezachem 616 Practically a Posting Shark

Show your code perhaps?

nezachem 616 Practically a Posting Shark

Don't bind a client socket. Use connect.

nezachem 616 Practically a Posting Shark

Your problem is that the line

comports[0]=CreateFile("\\\\.\\COM6", GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL,NULL);

is outside any function. Thus is is treated by compiler as a definition of a global array of size 0 with an initializer.
Move it into main, or some other appropriate function.

PS: Oops. Missed the second page.

nezachem 616 Practically a Posting Shark

What have you done so far?

PS: I am a psychic, but even I cannot tell the instruction set of

a pedagogical processor

nezachem 616 Practically a Posting Shark

It is meant to be a string array

However you define it as

std::string result;

that is a single string.

I am afraid AD didn't realize what you are trying to achieve and pushed you in the wrong direction. Disregard his advice from post #2, yet honor one from the post #4.

The memory allocated with new or malloc() in a DLL can not be deallocated by the main program part is absolutely correct, but it doesn't prevent you from returning such memory to main program. Just provide a helper method in the DLL to dispose what you returned. Of course the cleanest way is to wrap everything in a class.

nezachem 616 Practically a Posting Shark

Im still getting the wrong output

Of course. Now it is time to get the debugger and look closely to what buffer[8] and others are equal to. Hint: in C index of a first element is 0.

nezachem 616 Practically a Posting Shark
buffer[8] = ProcessID;

In C, x = y assigns a value of y to x. You assign a value of ProcessId to buffer[8]. That's what Dave Sinkula means by backward.

nezachem 616 Practically a Posting Shark
while ( ( current[14] = fgetc( file ) ) != EOF)

The program (repeatedly) reads the whole file, one character at a time, into the same byte, which also happen to be outside of the current array. What you want is

for(i = 0; (current[i] = fgetc(file)) != '\n'; i++)

provided that current has enough room to accomodate the whole line including the newline character.

The body of the loop is beyond criticism. Can you explain, line by line, what are you trying to achieve?

nezachem 616 Practically a Posting Shark
int counter;

You need to initialize it to 0.

Nick Evan commented: Nice catch, I should've seen that :) +12
nezachem 616 Practically a Posting Shark
(int)tmp[i]

Shouldn't it be VkKeyScan(tmp[i]) ?

nezachem 616 Practically a Posting Shark

First of all, in C you cannot compare strings with comparison operators. They only compare pointers, not the string data. You must use strcmp , as in strcmp(*mid, sample[0]) != 0 .

Next, I am afraid that dict are not what you think they are. They are dict array values, that is character pointers, which point to a more or less random locations. Each is valid, points a particular word, but the arithmetics on them makes no sense, and will cause crashes. What you want is dict array locations, that is &dict. Now the warnings will go away.

Beware that your code may try to access dict[20], which is beyond the array.

Finally, I would highly recommend to restructure your program a little bit.
A. read_words and read_text are in fact the same function; they just fill up different arrays. Get rid of one of them.
B. Do not pass the whole sample array to comparison routine. It only needs one word at a time.
C. comparison is a misnomer. It should be called search .

nezachem 616 Practically a Posting Shark

I don't see anything funny here. Time to get a debugger, I'd say.

nezachem 616 Practically a Posting Shark
out << quint16(0) << hello << version << clientType << length << identifier;

First of all, you are violating the protocol. As described, it requires that the packet starts with the length of the whole packet as a 4 byte value.

Second, Version and ClientType are one byte each; you define (and send) them as shorts, which is most likely 2 bytes.

It is more or less OK to send "hello" as quint16, provided that both server and client agree on the endianness. I know nothing about your server, and may only assume that it uses network byte order. In that case you'd have to find out how to set the QDataStream into network byte order (it accidentally is the same as big endianness).

nezachem 616 Practically a Posting Shark

A single computer may run a bunch of network applications simultaneously. Each incoming network packet must be routed to a particular one. Since the network layer has no idea of applications, the routing is done by means of ports. An applications (say, a server) binds its socket to a specific port, and a peer uses that port number as a part of destination address, so that the full address is ip:port, where ip identifies a computer, and port identifies an application (a socket, in fact) within that computer.

Ports are numbered from 0 to 65535. Some of them are assigned to specific servers. Everybody knows that port 80 is assigned to http server, port 22 to SSH etc. For a complete list of port assignments look at the IANA page.

Hope it helps.

nezachem 616 Practically a Posting Shark

Yet another buffer overflow, I suppose. How much space did you allocate for char buffer ?

nezachem 616 Practically a Posting Shark

If neither cygwin nor PowerShell is an option, you can try to play with FOR /F . Look here for examples.

Salem commented: Beaten ;) +18
nezachem 616 Practically a Posting Shark

Well, I'll be damned. You're a genius. I would have never have realized that.

I am not a genius. The difference between us is that you have a month of experience, and I have 30 years. Just keep in mind that mental debugging is only allowed to those who reach the third level of enlightenment. Until then you must use a debugger.

nezachem 616 Practically a Posting Shark

Look closely at line 26. You read one character, whereas user entered two of them: don't forget that she hit enter. This enter is consumed at line 18 next time around, which results in an empty username.

PS: do not use ascii codes in comparisons.

nezachem 616 Practically a Posting Shark

The answer is really simple indeed. You do append. You just print your roll incorrectly. Hint: why do you print the header inside the loop?

nezachem 616 Practically a Posting Shark
os.environ['junk']

should do it.

nezachem 616 Practically a Posting Shark

when I used Windows' ends of line in the text documents

That's exactly what I had in mind. Your environment may (and most likely does) differ from the server's. Treat end-of-lines correctly. Find out what's wrong with the last line testing (hint: restore it and step through the code with the debugger). I am sure the problems will go away.

nezachem 616 Practically a Posting Shark

A simple answer: you put 3 bytes into a 2-byte array.

What actually happens:
The arrays are allocated at the stack, next to each other, in order year/month/day (from lower addresses to higher). month[2] is the same as day[0]. A classic buffer overflow.

nezachem 616 Practically a Posting Shark

Another obvious bug is at line 101 (length of a last line is not tested).

Also, can you explain the logic of line 126, particularly a len-3 part? I strongly suspect your problem is there.

nezachem 616 Practically a Posting Shark

Do not use list. Keep your objects in a dictionary indexed by coordinate tuple.

nezachem 616 Practically a Posting Shark

As far as my understanding and other referals i understood that when the address
of a local variable is returned the first call using this address may print the correct
value but if it is called after any other function may get undefined values.

but my program is returning the value that is equivalent to address.

please some one help me in understanding this.

int * first();
int * second();

int main()
{
	int *f, *s ;
	f = first();
	printf(" After calling first : value of f ( %p ) \n", f);
	printf(" After calling first : value of *f ( %x )\n", *f);

the out i am getting is :

In First : value of f_lcl ( aaaa )
In First : addr of f_lcl is ( bff4f2c4 )
After calling first : value of f ( 0xbff4f2c4 )
After calling first : value of *f ( bff4f2c4 )
)

f is the address of the local variable, correct. The local variable has been allocated at the stack at the time first was running. Now you invoke printf. The parameters passed to printf are allocated at the stack as well, overwriting whatever may have left there. By pure luck (*) the used-to-be local variable gets overwritten by the second parameter of the call. So, after the first call to printf this stack location contains f, that is the address. When you call printf the second time, *f is evaluated prior to moving parameters to …

nezachem 616 Practically a Posting Shark

One thing more, the driver is the device driver for the keyboard, na ?

No.
Open a binary editor. Create a file having "Hello^Zworld" in it. Save it as foo.txt. Now at the prompt type copy foo.txt bar.txt . At the next prompt type copy /b foo.txt baz.txt . Finally, with the same binary editor compare contents of bar.txt and baz.txt. Notice that the console was not involved.
The ^Z does signify the end of any text mode stream regardless of its origin. Yet again, the application will never see it. Instead, whoever feeds stream data to application closes it, the same way that whoever closes the binary mode stream when the stream data are exhausted.
It is important to understand, that all stdio functions (not just getchar) obey this protocol.

In contrast to it, getchar() must be working on a text stream, that's why the following condition is satisfied :

while ((a=getchar())!=EOF);

when we press ctrl+z.

getchar works on the stream in the very same mode the stream currently operates. It is just happens so that by default stdin is in the text mode. It is not a rocket science to reopen stdin in binary mode, after which getchar would happily return 26 on ^Z. It is also enlightening to printf ^Z, and see what happens to stdout.
It is important to understand, that all stdio functions (not just getchar) obey this protocol.

When we write this :

printf ("%d",getch());

and press ctrl+z, we get …

nezachem 616 Practically a Posting Shark

getch() returns 26 (ascii for ctrl+z, which indicates the end of input in Windows)

That's a very usual misconception. First of all, ctrl+z is only significant for text mode streams. Second, for text mode streams, ctrl+z is handled by the driver. It is the driver who encounters ctrl+z, and in response it closes the stream. An application would never read ctrl+z; it hits an end of file instead.
For a binary mode streams, ctrl+z is an ordinary character.