gerard4143 371 Nearly a Posting Maven

i have no clue where or how to start, any idea would be immensely helpful..

If I was doing this 'but I'm not' I would investigate here

http://epaperpress.com/lexandyacc/

Redhaze46 commented: thanks:) +1
gerard4143 371 Nearly a Posting Maven
Ancient Dragon commented: Good point. I rewwrote it in C language. +33
gerard4143 371 Nearly a Posting Maven
cwarn23 commented: Great link and quick response. Thanks heaps. :) +5
gerard4143 371 Nearly a Posting Maven

Thanks faxo and ancient dragon. Ancient Dragon i tried out your code however no value was printed out. Faxo, I also think its a good idea to use the fgets. However it should have been just gets since i'm not dealing with files over here.

Not sure what you mean by 'should have been just gets since i'm not dealing with files over here'...It really doesn't matter, gets(char*) is dangerous...

BUGS
Never use gets(). Because it is impossible to tell without knowing the
data in advance how many characters gets() will read, and because
gets() will continue to store characters past the end of the buffer, it
is extremely dangerous to use. It has been used to break computer
security. Use fgets() instead.

gerard4143 371 Nearly a Posting Maven

This is what my help files say about fgets return value...

char *fgets(char *s, int size, FILE *stream);

gets() and fgets() return s on success, and NULL on error or when end
of file occurs while no characters have been read.

gerard4143 371 Nearly a Posting Maven

When a function returns, it uses whatever is in the %rax register as its return value. Your function may inadvertently be placing the right value in %rax.

Note: I won't rely on this behaviour.

gerard4143 371 Nearly a Posting Maven

Woah...Don't use gets(). You run the risk of a buffer overflow, instead use fgets().

gerard4143 371 Nearly a Posting Maven
Ancient Dragon commented: Very useful link :) +28
gerard4143 371 Nearly a Posting Maven

Ed would say that there is no difference because the whims of the compiler are irrelevant when it comes to the validity of a program. The program *has* to behave a certain way, regardless of how the compiler makes it happen.

Its relevant to me....and here's a link about referring to yourself in the third person

http://uncyclopedia.wikia.com/wiki/HowTo:Refer_to_Yourself_in_the_Third_Person

gerard4143 371 Nearly a Posting Maven

Why not just have an accumulator and keep a running total there.

sum = 0;
sum += getInt();
Don_k commented: FOR YOUR IMMEDIATE RESPONSE TO MY QUESTION FROM DON_K THANK YOU +1
gerard4143 371 Nearly a Posting Maven

I know that qt and gtk+ provide extensive documentation...plus you'll find numerous tutorials on the internet.

gerard4143 371 Nearly a Posting Maven

this cant possibly be that hard to answer?

Like you said "this cant possibly be that hard to answer". I just google C >> and checked wiki C/Operators and there they were...


http://en.wikipedia.org/wiki/C_%28programming_language%29

camdaddy09 commented: didnt help at all +0
gerard4143 371 Nearly a Posting Maven

What happened? Did an eggplant blow up in here?

jephthah commented: perfect +0
Nick Evan commented: :) +0
gerard4143 371 Nearly a Posting Maven

The parentheses are optional when applying sizeof to a variable.
p = malloc(sizeof words );

Now I didn't know that. I guess that's why I keep coming back.

gerard4143 371 Nearly a Posting Maven

Your problem is this line right here

ipray[i] = *tok;

Which doesn't do what you think it does.

Take a look at this version which is a simplified version of your code and is correct...Now all you have to do is convert the values to integers or copy them to the character array.

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

void truncat(char str[], char ipray[]);

int main()
{
	char str[16];
	char ipray[4];

	printf("Enter a Netmask :");
	scanf("%s", &str[0]);

	truncat(str, ipray);

	return 0;
}

void truncat(char str[], char ipray[])
{
	char *tok;
	int i = 0;

	tok = strtok(str,".");

	while (tok != NULL)
	{
		fprintf(stdout, "tok->%s\n", tok);
		tok = strtok(NULL, ".");
	}
}
gerard4143 371 Nearly a Posting Maven

I have a question, well more of a verification.

In the program below, I'm packing a character array with some values. The first two are unsigned integers the next is a function pointer and the final is a string of characters...Now my question, is the casting correct for the function pointer? Just check the sections marked off with /*this section*/.

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

#define MAXLINE 4096

char *ca = "this is the string to pass";

void myhello(void)
{
	fputs("Hello, World!\n", stdout);
}

int main(int argc, char**argv)
{
	unsigned int i = 0;
	char recvline[MAXLINE];

	*(unsigned int*)&recvline[0] = 11111;
	*(unsigned int*)&recvline[sizeof(unsigned int)] = 22222;
 
	/*this section*/
	*(void(**)(void))&recvline[2 * sizeof(unsigned int)] = (void(*)(void))&myhello;
	/*this section*/

	for (i = 0; i < strlen(ca); ++i)
	{
		recvline[2 * sizeof(unsigned int) + sizeof(void*) + i] = ca[i];
	}

	fputs("\n\ndisplay packed character array\n\n", stdout);

	fprintf(stdout, "number one->%u\n", *(unsigned int*)&recvline[0]);
	fprintf(stdout, "number two->%u\n", *(unsigned int*)&recvline[sizeof(unsigned int)]);

	fputs("call function myhello->", stdout);
	/*this section*/
	(*(void(**)(void))&recvline[2 * sizeof(unsigned int)])();
	/*this section*/
	
	fprintf(stdout, "string->%s\n", &recvline[2 * sizeof(unsigned int) + sizeof(void*)]);
	return 0;
}
gerard4143 371 Nearly a Posting Maven

If the cross-complier is already setup then it shouldn't really be a problem...Program as usual but run the programs on your embedded system...If your looking for tuts and docs try googling GCC embedded systems

http://www.linuxjournal.com/article/9904

gerard4143 371 Nearly a Posting Maven

Your scanf should be reading the data into the address of the structure members..

&info.number

jephthah commented: good job. you are all over this. +7
gerard4143 371 Nearly a Posting Maven

Try running this code...What do you notice about the output. Is match different than str?

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

char match[] = "123";

int main(int argc, char**argv)
{
	char str[25];

	fputs("enter a value->", stdout);
	fgets(str, 25, stdin);
	

	fputs(str, stdout);
	fputs(match, stdout);


	exit(EXIT_SUCCESS);
}
Aia commented: A good starting point +8
gerard4143 371 Nearly a Posting Maven

Sounds like your having problems understanding functions...Check out this link

http://www.mycplus.com/tutorials/c-programming-tutorials/functions/

gerard4143 371 Nearly a Posting Maven
int max_temp(measured_data_t id, measured_data_t temperature, , int *ID, int *max_temp);

You have two , , with no parameter. Probably should be

int max_temp(measured_data_t id, measured_data_t temperature, int *ID, int *max_temp);
gerard4143 371 Nearly a Posting Maven

You really shouldn't mix cout and printf especially on the same line...When you have this

<<printf("whatever")

You'll print out the result of calling printf which is four characters in your code.

gerard4143 371 Nearly a Posting Maven

why is there a + infront of 100k but a - infront of 500k?

You really should familiarize yourself with manpages

TESTS
       Some  tests,  for  example  -newerXY  and  -samefile,  allow comparison
       between the file currently being examined and some reference file spec‐
       ified  on the command line.  When these tests are used, the interpreta‐
       tion of the reference file is determined by the options -H, -L  and  -P
       and any previous -follow, but the reference file is only examined once,
       at the time the command line is parsed.  If the reference  file  cannot
       be  examined  (for  example,  the stat(2) system call fails for it), an
       error message is issued, and find exits with a nonzero status.

       Numeric arguments can be specified as

       +n     for greater than n,

       -n     for less than n,

       n      for exactly n.
gerard4143 371 Nearly a Posting Maven

Did you try investigating setjmp, longjmp.

Also sometimes, for efficiency, goto's are the best solution.

gerard4143 371 Nearly a Posting Maven

I need the coding for the following question in C:
Read and print all the consonants from a file (no duplicates). Assume the file is a .txt file. The consonants are then to be sorted in alphabetical order.

Again, read this

http://www.daniweb.com/forums/announcement118-2.html

gerard4143 371 Nearly a Posting Maven

hi there i have an assignment about writing Cshell with some features i m not gonna ask plz gimme the codes or smth. but i need some advice how to start writing it, what to do maybe smn can show me ways to do it , thanks for help

here is the assignment :

here are the minimum requirements of the shell you are required to write.
1. It should be able to run all the single-process commands.
2. It should be able to run all the two-process pipelines, the skeleton of which is as given in Fig. 1–13 of the
text.
3. It should be able to handle input and output redirection.
4. It should be able to execute commands in the background.
You are, of course, free to add more features to the shell you write.

This isn't a homework completion forum. We help people who show an effort and have specific problems...Please see this link

http://www.daniweb.com/forums/announcement118-2.html

gerard4143 371 Nearly a Posting Maven

but its not working as i expected.

What were you expecting...my crystal ball's on the fritz and the Amazing kreskin is busy right now..

jephthah commented: i'm always partial to sarcasm. ;) +6
gerard4143 371 Nearly a Posting Maven

hey guys !:)
well (00401034 . 322E XOR CH,BYTE PTR DS:[ESI])
and
(00401031 ,65:72 33 JB SHORT messagee.00401067) these are out of ollydbger:)
compare them both
and can u tell me if the middle column i mean 322e n 65:72 33
are the same?
like 657233h is the same as 65:72 33 ?
pls help me is this an example of virtual address or more of a virtual command or something??

Is this posting supposed to make sense or something?

gerard4143 371 Nearly a Posting Maven
sed -n '6,11p' file1

Show-off

gerard4143 371 Nearly a Posting Maven

I need to create a shell script which will output certain lines in a file. For example ./line file1 6 11 will output lines 6 to 11 of the file. I am not good at shell script, I am a beginner. I have tried to write this script but just cannot. If anybody can help by giving me a website similar to this problem, please send it thanks.

Try using the while loop and command parameters

#! /bin/sh

echo -n "enter filename->"
read myfile

while read f
do
	echo "line $((++cntr)) is->$f"
done < $myfile

You should be able to figure the rest out..

gerard4143 371 Nearly a Posting Maven

Hi,
I was looking at this tutorial:

http://linuxgazette.net/77/krishnakumar.html

There's an instruction there that says "seg es", my question is whats this instruction in AT&T style? I'm trying to rewrite the code in AT&T syntax and use it with gcc/ld but it gives me an error: "kernel.s:6: Error: no such instruction: `seg %es'"

Any help appreciated!

Best regards,
Keith

I won't go by that syntax if you using GCC/AS..

This about the same thing

.code16

.section .data

.scetion .text
	.global _start
_start:
			movw	$0xb800, %ax
			movw	%ax, %es

			movb	$0x41, %es:0
			movb	$0x1f, %es:1

			movb	$0x34, %es:2
			movb	$0x1f, %es:3

			movb	$0x31, %es:4
			movb	$0x1f, %es:5

			movb	$0x34, %es:6
			movb	$0x1f, %es:7

			movb	$0x33, %es:8
			movb	$0x1f, %es:9
loop1:
			jmp	loop1
keithodulaigh commented: Thanks, exactly what I needed. +0
gerard4143 371 Nearly a Posting Maven

what is lvalue required in turabo c++,Hoe i can solve this type of error?

Its probably means you need to have an assignable value on the left hand side..

example:

#include <stdio.h>

int main(void)
{
	int x = 0;
	5 = x;
	return 0;
}

generates a compile error

error: lvalue required as left operand of assignment

because 5 is a literal

gerard4143 371 Nearly a Posting Maven

Sure just type

firefox www.google.com

gerard4143 371 Nearly a Posting Maven

here's a blurb from my man help file about gets()

BUGS
Never use gets(). Because it is impossible to tell without knowing the
data in advance how many characters gets() will read, and because
gets() will continue to store characters past the end of the buffer, it
is extremely dangerous to use. It has been used to break computer
security. Use fgets() instead.

Salem commented: Damn straight! +19
gerard4143 371 Nearly a Posting Maven

hi
when I use this with my program i have msg tell me about the warning in my program

please any one explain it

thanks

ggdb

`-ggdb'
Produce debugging information for use by GDB. This means to use
the most expressive format available (DWARF 2, stabs, or the
native format if neither of those are supported), including GDB
extensions if at all possible.

GDB, the GNU symbolic debugger

gerard4143 371 Nearly a Posting Maven

IF i write to file REGISTRATION NUMBER :1001 how can read back from the file the 1001.

Thank you for all your help,i have gotten other hints but they don't seem to work

Well lets see what you've done with some of your hints.

gerard4143 371 Nearly a Posting Maven

scanf("%f", restart);

should be

scanf("%f", &restart);}

gerard4143 371 Nearly a Posting Maven

The rule is - for every malloc you call, you have to call free..

Salem commented: Yes. +19
gerard4143 371 Nearly a Posting Maven

Most C++ compilers offer a setting to stop compiling..

In GNU its

g++ file.cpp -S

`-S'
Stop after the stage of compilation proper; do not assemble. The
output is in the form of an assembler code file for each
non-assembler input file specified.

gerard4143 371 Nearly a Posting Maven

Is there a question hidden in your posting?

gerard4143 371 Nearly a Posting Maven

I figured my stupid silly mistake. children[i+degree] is not a pointer. What punishment do you suggest to give johndoe for such a moronic act?

How about getting you to post this in the C++ section

Note: I used g++ to compile this. How to change things to compile without error for g++?

jonsca commented: Yes +2
gerard4143 371 Nearly a Posting Maven

Is this me or does this look like C++

list<item_set> candidate_set;

gerard4143 371 Nearly a Posting Maven

Because the compiler padded the structure elements up to whole bytes.

one byte for signed int a:3;
two bytes for unsigned int b:13;
and on byte for unsigned int c:1;

Try using the attribute packed like below and you'll get three bytes because again the compiler will pad the end of the structure up to wholes bytes..

#include <stdio.h>

int main(int argc, char* argv[])
{
        struct bitfield
        {
                signed int a:3;
                unsigned int b:13;
                unsigned int c:1;
        }__attribute__((packed));
        struct bitfield bit1={2,14,1};
       
	fprintf(stdout, "size of a->%lu\n", sizeof(bit1));

        return 1;
}
gerard4143 371 Nearly a Posting Maven

Here's an example of dup2, its was for someone who posted a pipe question here at daniweb...I forgot to post it so you can use it as an example

What does the program do? It forks for each row in the array and each child adds the array elements of its row and then reports the values back to the parent which sums them.

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <signal.h>

#define ARR_ROW 5
#define ELEMENTS_PER_ROW 3

unsigned long longarray[ARR_ROW][ELEMENTS_PER_ROW] = 	{
								{1, 2, 3},
								{4, 5, 6},
								{7, 8, 9},
								{10, 11, 12},
								{13, 14, 15}
							};

enum PIPES {READ, WRITE};

int main(int argc, char**argv)
{
	unsigned long i = 0, tot = 0; 
	int hpipe[2];
	char ch[10];

	signal(SIGCHLD, SIG_IGN);
	pipe(hpipe);

	for (i = 0; i < ARR_ROW; ++i)
	{
		if (fork())
		{
		
		}
		else
		{
			int j = 0; 
			unsigned long ans = 0;
			close(hpipe[READ]);
			dup2(hpipe[WRITE], 1);
			close(hpipe[WRITE]);
			for (j = 0; j < ELEMENTS_PER_ROW; ++j)
				ans += longarray[i][j];
				
			fprintf(stdout, "%lu\n", ans);

			exit(EXIT_SUCCESS);
		}
	}

	close(hpipe[WRITE]);
	dup2(hpipe[READ], 0);
	close(hpipe[READ]);

	for (i = 0; i < ARR_ROW; ++i)
	{
		fgets(ch, 10, stdin);
		tot += strtol(ch, NULL, 10);
	}

	fprintf(stdout, "parent received a total of->%lu\n", tot);
	exit(EXIT_SUCCESS);
}
gerard4143 371 Nearly a Posting Maven

Right from my linux/GNU man file

BUGS
Never use gets(). Because it is impossible to tell without knowing the data in advance
how many characters gets() will read, and because gets() will continue to store charac‐
ters past the end of the buffer, it is extremely dangerous to use. It has been used to
break computer security. Use fgets() instead.

Salem commented: Indeed, it is so. +19
gerard4143 371 Nearly a Posting Maven

You realy should google C functions and C control statements....You'll find the answers in these queries...

gerard4143 371 Nearly a Posting Maven

About

gets(name);

This is what manpages has to says about gets()

BUGS
Never use gets(). Because it is impossible to tell without knowing the
data in advance how many characters gets() will read, and because
gets() will continue to store characters past the end of the buffer, it
is extremely dangerous to use. It has been used to break computer
security. Use fgets() instead.

Salem commented: Damn straight! +19
gerard4143 371 Nearly a Posting Maven

Volatile tells the compiler that a variable may be changed in ways not explicitly specified by the program - According to C: The complete Reference. This means the volatile variable may be changed by forces outside of the current process(usually the kernel, hardware or another process) so don't make any assumption about its current value...

gerard4143 371 Nearly a Posting Maven

Check this posting for a pipe example:

http://www.daniweb.com/forums/thread258136.html

gerard4143 371 Nearly a Posting Maven

how about this kind of pyramid?
*
* * *
* * * **
* * * * * * *
* * * * * * * * *

Yeah. How about it?

Nick Evan commented: :) +12