gerard4143 371 Nearly a Posting Maven

Is this the proper way to zero the first 12 bits of an address?

void *ans = (void*)((unsigned long)addr &  ((0UL - 1)  ^ 0xfff));

Where addr is any user process memory address..

Note this method works...I just want to know if there is a better way

gerard4143 371 Nearly a Posting Maven

So far I have my C file taking in 2 characters:

char char1, char2;
    printf ("Enter a character: ");
    scanf ("%c", &char1);
    
    while (getchar () != '\n')//so that the program doesn't take in the carriage return as input
        continue;
    
    printf ("Enter another character: ");
    scanf ("%c", &char2);
    
    while (getchar () != '\n')//so that the program doesn't take in the carriage return as input
        continue;

And I'm just not sure how to verify if their HEX or just normal characters (so either 0-9 or A-F). I was thinking I could just do a bunch of if statements comparing each of them (or make a HEX array, and for loop through it comparing along the way), but is there a better way to do this?

C has a function called isxdigit which checks if the character is 0 -9 or a - f maybe you could use that...

gerard4143 371 Nearly a Posting Maven

Hi!

I have had to change from Python to C because of university instructions. My problem is that, when I want to make a menu for my program or whatever, I always want to define classes:P

My question is simple --> are structures the best way to "replace" classes?

TY

Well yes...if you think of structures as classes without methods and constructor/destructors

Well if you want to get technical - a structure can contain a pointer to a function which is kind of like a method(in the loosest definition)

gerard4143 371 Nearly a Posting Maven

Could we see what you have so far?

gerard4143 371 Nearly a Posting Maven

Hey everyone,

For my project, I need to write an assembly/C code to detect multiprocessors. I really have no idea how as I have barely done assembly coding and I have no good reference or even idea how to start. Again, what I am going to do is, I'm trying to find how many processors on dual core or quad core chips there are and detect them and later on use them. Please help me out here.

Thanks a lot.

Can you use the opcode cpuid to query the functionality of the processor because I'm looking at the AMD doc's and cpuid provides Logical processor count

gerard4143 371 Nearly a Posting Maven

Which run time error would that be?

gerard4143 371 Nearly a Posting Maven

I need a function that returns the name of a key directly from the keyboard, eg, the input of '32' would return 'Space'.

I know there is a function that does this, but I can't figure out which one.

I know this is knit picking but....You can't get the name of the key "directly" from the keyboard, its generally via the operating system's kernel....I know knit picking

gerard4143 371 Nearly a Posting Maven

If your talking about wireless then I never had any problems with Mandriva..I also use Gnome but with this version I'm going to give KDE a try, maybe just maybe they have the bugs worked out..

Switched back to Gnome already...

gerard4143 371 Nearly a Posting Maven

yes, it looks quite promising. not a big KDE4 fan though, so will be giving GNOME a go. proceeding with caution though, as i have an intel chipset and my machine hates both the new ubuntu and fedora

If your talking about wireless then I never had any problems with Mandriva..I also use Gnome but with this version I'm going to give KDE a try, maybe just maybe they have the bugs worked out..

gerard4143 371 Nearly a Posting Maven

Mandriva 2010 has just been released

http://www2.mandriva.com/downloads/

gerard4143 371 Nearly a Posting Maven

I passed this posting numerous times and I always wondered how do you define what your string is...i.e. can your string span more than one line in your text file, can your string overlap, can it overlap many times...with these questions bouncing around in my head the only way I can find to interrogate a text file is to start with the first character and check the preceding characters to see if you have a match, if you do increment count if not move to the next char and check the preceding characters....

Note with this method you have to disregard newline characters

gerard4143 371 Nearly a Posting Maven

How do I generate random numbers in C? The user doesn't enter anything, I'm just looking for a way to generate random numbers every time I run the program.

Thanks guys!

I would lookup random or srandom...for pseudo random functions in C

gerard4143 371 Nearly a Posting Maven

But, is there any proposed solution to what I'm looking for?

Your comparing a array of characters(char input[50]) that is supposed to be a C style string("abc")...I would investigate string compare functions

gerard4143 371 Nearly a Posting Maven

Well I'm supposed to use the struct that they showed declared in sched.c but there is no sched.c... I am supposed to use it and then point to what I need, example:
task->pid == 1234

I am supposed to "read the task kernel variable"...
Any ideas on how to set up this struct and use it?

Do you have the source code down loaded for your kernel?

gerard4143 371 Nearly a Posting Maven

Hmm...no man, that only makes it a LOT worse, but thanks for trying. I appreciate it. Here's some rep ;)

I said it should probably be - you have some very serious errors in your code. The foremost is you don't know how to call a function..

gerard4143 371 Nearly a Posting Maven

This is line 111

height_earth = double distance_earth(float speed, double radians)* (tan(radians)) - (G_earth * (pow(double distance_earth(float speed, double radians), 2))) / ((2(pow((speed)(cos(radians), 2)))));

should probably be:

height_earth = distance_earth(speed, radians)* (tan(radians)) - (G_earth * (pow(distance_earth(speed, radians), 2))) / ((2(pow((speed)(cos(radians), 2)))));
A Tripolation commented: thanks man +1
gerard4143 371 Nearly a Posting Maven

I'm looking at you main function I can't see where your calling any function to initialize your array.

shouldn't you be calling
void init_board();
void print_board()

yellowSnow commented: A good and fast response. +2
gerard4143 371 Nearly a Posting Maven

hello, i'm making program which repeatedly (through while) gets input from the user ... program should stop whenever user enters "\n" (or enter button)!

thanks in advance!

If you mean exit the loop then use break...if you mean exit the program then use exit(EXIT_SUCCESS);

If you want to get fancy you could explore setjmp...

gerard4143 371 Nearly a Posting Maven

Orrrrr you could open a terminal and type uname -a to get most of the info

gerard4143 371 Nearly a Posting Maven

Thanks for quick reply. What do you mean by num and num2 in the above code. Will i have to declare num and num2.

Its just an example that I made up..The numbers signify nothing.

gerard4143 371 Nearly a Posting Maven

try two for loops...one embedded into the other

for (i = 0; i < num; ++i)
{
for (j = 0; j < num2; ++j)
{}
}
gerard4143 371 Nearly a Posting Maven

All I was looking for was the file names....Oh well
If you have the files compiled to object files then all you have to do is collect them together for the final linking/compiling...

g++ ErrorHandlingModule.o PromptModule.o main.o -o exefilename -lcrypt -lm

I'm assuming the switches at the end are correct(I got them from your original posting)

Also a great thing to learn is creating makfiles...here's a link

http://makepp.sourceforge.net/1.19/makepp_tutorial.html

gerard4143 371 Nearly a Posting Maven

If you could list your files, I will show how to compile and link them

gerard4143 371 Nearly a Posting Maven

Whoops my bad...Please disregard the following

gerard4143 371 Nearly a Posting Maven

Which debugger are you using?

gerard4143 371 Nearly a Posting Maven

Thanks pal, you are really for me. I appreciate it.
Best regards.

If your looking for a good 32/64 bit disassembler that works in Linux then check out Biew at:

http://biew.sourceforge.net/en/biew.html

gerard4143 371 Nearly a Posting Maven

can i have more details about dynamic and static

Sure the internet is full of details....try Googling

gerard4143 371 Nearly a Posting Maven

thanks but it doesn't actually helped me.
I will ask you more simple request :
I want to Update the kernel , that if one process wants to open a file , then we print to the screen " process %pid tries to open the file %file"
thanks in advance.

Well when you hijack the system call make sure it prints a message to the screen when a process opens or closes a file...I'm not sure what your looking for...I gave you a coded example and from that you should be able to get all the info you need...

gerard4143 371 Nearly a Posting Maven

List at least two possible ways for linking against the math library.

static and dynamic

gerard4143 371 Nearly a Posting Maven

it's an assignement and i have to get info about kernel in unix hows it works ...

Did you read the first reply I posted?

gerard4143 371 Nearly a Posting Maven

thanks for your help. I tried objdump and I got a clear code. add [bx+si],al are lost. Are you sure it is de-compiler problem? Can it be something important about program?
The program writes on screen. Can it be related with writing operation?

Like I said its probably the header or footer information that's added to the exe. This information. header/footer is used by the linker and operating system...

If you really want to see what's in your file then open it in a hexeditor and check the result against the objdump. You'll easy see where the header, footer and your code begins and ends.

gerard4143 371 Nearly a Posting Maven

If you have an error message please...please copy it down and pass it on to us...

gerard4143 371 Nearly a Posting Maven

Hi fellas,
I have a question about disassembled code. I have a very simple assembly code that prints "Hello world" to screen. When I disassembled it by using nasm(ndisasm), I got a text file. After that I opened it and started to analyze it. However, in a section that comes after " int 0x80" there are a lot of "add [bx+si],al" statement. What does it means? Can you explain me?

Depends really...it could be a bunch of data that the de-compiler is having trouble with...more likely, its just the header or footer information that comes with every executable...If you want to look your code try objdump instead. Objdump conveniently removes all this extra data...

gerard4143 371 Nearly a Posting Maven

I am working in Linux 2.14 kernel, and I have an assignment.
I want to save for every process , the files it opens and closes , and the time he did that.
for example :
for process aaa :
opening "file1"
opening "file2"
closing "file1"
opening "file3"
closing "file3"
closing "file2"
I could save a linked-list , the question is where to save that , and how to update it.

If its an old kernel then hi-jack the system calls and get then to send some information to the log file...here's an example of hi-jacking a system call

http://www.faqs.org/docs/kernel/x931.html

gerard4143 371 Nearly a Posting Maven

thx plz i cant find it
can someone help

Maybe if you explained t us what "it" is...

gerard4143 371 Nearly a Posting Maven

plz plz urgent im a beginner in unix.
can someone reply asap .
what are kernel modules?what role do they plan in building and runnig a kernel?what happens if the linux kernel did not support modules?

Here's a good link to get you started

http://tldp.org/HOWTO/Module-HOWTO/

gerard4143 371 Nearly a Posting Maven

Thanks for the reply. Yes, I know how to use assembler within C code. But the question is if it is possible to get the program counter of a another program of which the source code should not be altered!


MyProg --->get the program counter --> UnkownProg

Thanks in advance,
svkers

So what your after is - get the program counter of another current program running on a different core from the current calling program? Multi-core right? Because how could you have more than one current on a single core...

You'll probably have to consult the AMD/Intel manuals for this one...

gerard4143 371 Nearly a Posting Maven

Can we see what you have so far?

gerard4143 371 Nearly a Posting Maven

I am trying to write a program that will input a bunch of names into an array of structures under the .name heading. Currently I have what is below to get it to work. But it's not very flexible. You have to input both a first and a last name before it will go on. Is there any command similar to cin.getline for C++ that will work in this instance? Or a way to leave last as null if a second ("last") name isnt input that time around?

for (count_s=0; count_s < num_stu; count_s++){
        printf("\nEnter name of student #%i: ",count_s+1);
        scanf("%s %s", &first, &last);
        strcpy(student[count_s].name, first)
        strcat(student[count_s].name, " ");
        strcat(student[count_s].name, last);
        
    }

Do you mean like C's getline function?

gerard4143 371 Nearly a Posting Maven

Your error message - did it tell you what line the error is on?

Because just guessing I would have to say its this line:

displayArray(nArray[arraynum]);

because nArray[arraynum] is an integer not an array of integers

gerard4143 371 Nearly a Posting Maven

Thanks but I'm not using Linux. I'm using the Dev compiler and have it saved as a .c file.
UPDATE
I wrote a user defined function and I am getting the same undefined reference error when I try to call this function.

Dumb question...Has this compiler worked before? i.e.have you successfully compiled other programs with this setup.

gerard4143 371 Nearly a Posting Maven

Hello friends. I am experiencing problems using the getline function in C. I want to use the function to print line numbers next to the text of each line of an input file. I have successfully read in the file and printed its contents line by line. But when I add the part to print the line numbers using getline, the compiler reports an error and the code doesnt run.
Here is the error I am getting

[Linker error] undefined reference to `getline' 
  ld returned 1 exit status

Here is the code I am using:

#include <stdio.h>
#include <string.h>
# define NEWLINE '\n'
int main()
{
    static const char filename[] = "Bond.in.txt";        
    FILE *file = fopen(filename, "r");    
    if ( file != NULL )
   {
     char line [ 200 ]; 

      while ( fgets ( line, sizeof line, file ) != NULL ) /* read a line */
      {
         fputs ( line, stdout ); /* write the line */
      }
/*********** code that gives problem ***********/

int counter = 0;
while ( getline(&filename, &line, stdin) ) 
{
    ++counter;
    printf( "%d , %d", counter, line);	
}

/************* end of code that gives problem****/

      fclose ( file );
   }
   else
   {
      perror ( filename ); 
   }
       char wait;
    scanf( "%c", &wait );
   return(0);
}

I dont understand where this error is coming from. I tried several varaitions using different parameters for getline but all resulted in the aformentioned error. It is my understanding that getline is a built in function included in the stdio library. …

gerard4143 371 Nearly a Posting Maven
gerard4143 371 Nearly a Posting Maven

If you installed a 64 bit version of Linux on a 64 bit box, then the default compiler(gcc) will produce 64 bit code...that is unless you set the appro. switches telling it to produce 32 bit code...

gerard4143 371 Nearly a Posting Maven

For starters, you might want to move this above the main() function like:

void swap(int *, int *); //prototype with a pointer parameter

int main()
{
...
}
gerard4143 371 Nearly a Posting Maven

some one help write a program to calculate the sum of the first 20 integers

We can't/shouldn't write it for you...but we can provide pointers if you show some effort. So what do you have so far...

gerard4143 371 Nearly a Posting Maven

This line should probably be:

char *frases[cantidad_frases];

char *frases = (char*)malloc(cantidad_frases);

So that you have allocated the memory...

gerard4143 371 Nearly a Posting Maven

Are you requesting links to C programming tutorials?

gerard4143 371 Nearly a Posting Maven

Hi all!
Please somebody explain me how this snippet is working!!

main()
{
float a 4.379;
char*p;
int i;
p=(char*)&a;
for(i=1;i<=3;i++)
printf("%02X",(unsigned char)p[i]);
}

The code simply assigns the address of "a" to the character pointer "p" and then proceeds to check the value of the four bytes at address p[0], p[1],p[2], and p[3]...

gerard4143 371 Nearly a Posting Maven

This should be moved to the C++ section...