gerard4143 371 Nearly a Posting Maven

@gerard4143 : I can't use dlls, I have a restriction.
@Dave : The first example is working, the structure gets populated with values in the inc file.

Thanks for the replies.

Ok, if its not possible then is there any other way to populate this structure using the inc files without using #include?

I'm not really sure what your after...but you could try working with a marco..

Note - Marcos are processed by the preprocessor as well

gerard4143 371 Nearly a Posting Maven

The include statement is processed by the preprocessor so it can't be dynamically created in the executable...

If you want to do this try Dlls

gerard4143 371 Nearly a Posting Maven

Hello people :)

My teacher gave me a new project to work on.
I need to write an application that output all the letters of the alphabet in a random order.
I've made some applications before but im still kinda new to this.
Could any of you give me a hint or put me in the right direction?

Kind regards,
Jelmund

PS: i already searched on the internet

What do you have so far?

gerard4143 371 Nearly a Posting Maven

Did you even look at what I posted?

gerard4143 371 Nearly a Posting Maven

Or up and down. It doesn't matter. It is undefined behavior.
If a plane doesn't have a pilot, it doesn't matter if people speculate about the capacity of fuel tanks to make the trip, or the condition of weather in the area, or even how much weigh can handle. It can not make the trip.

He wanted to know why and that's probably why. One compiler set up the assembled code to read the values left to right and one set up the values to be read right to left. Like you said the language leaves this behavior undefined so its up to the compiler designers to decided which method L -> R or R -> L.

And your analogy...Is that supposed to make sense...

gerard4143 371 Nearly a Posting Maven

ohk...

but why are the two values , printf("\n%d",i++ + ++i + i++ + --i); and printf("\n%d",c);
different?

Because you don't set i back to 5

c=i++ + ++i + i++ + --i;
i = 5;////set i back to five
printf("\n%d",i++ + ++i + i++ + --i);
printf("\n%d",c);
gerard4143 371 Nearly a Posting Maven

include<stdio.h>
void main()
{
int i=5;
int c;
c=i++ + ++i + i++ + --i;
printf("\n%d",i++ + ++i + i++ + --i);
printf("\n%d",c);
}
The o/p that I'm getting is
31
23

while my friend got
34
20.


Also why are the 2 (printf ' c 'and printf 'expression') values different. Is it because printf evaluation is different from how a normal expression would be evaluated?

thanks in advance.

It probably depends on how the compiler evaluates the expressions...left to right
or right to left...

gerard4143 371 Nearly a Posting Maven

check out what I did here, I put three fprintf lines in here to check the values you are entering in your char**...Also this program had many errors...It won't compile for me so I changed some of it

Also why do you use a function pointer????

Note I quickly went through the code so I probably missed some things

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

#define MAXLEN 100
void fnRemChar(char*,char);
int main(int argc,char *argv[])
{
	int iCount=0;
    system("clear");
    int iNoOfStr;
    char acInpStr[MAXLEN][MAXLEN];
    char cChar;
    printf("\nEnter number of strings to be entered(should not be greater than %d):",MAXLEN);
    fflush(stdin);
    scanf("%d",&iNoOfStr);
    void (*REMOVE) (char* ,char);

        /* REMOVE Pointer to Function fnRemChar */
        REMOVE = fnRemChar;//function pointer????

	getchar();

    for(iCount;iCount<iNoOfStr;iCount++)
    {
        printf("\n ENTER %d String: ",iCount+1);
        fgets(acInpStr[iCount],MAXLEN,stdin);
        //fflush(stdout);
        //fflush(stdin);
    }
	fprintf(stdout, "s->%s\n", acInpStr[0]);//check first three
	fprintf(stdout, "s->%s\n", acInpStr[1]);//check first three
	fprintf(stdout, "s->%s\n", acInpStr[2]);//check first three
    printf("\n Enter character to be removed: ");
    scanf("%c",&cChar);

    for(iCount=0;iCount<iNoOfStr;iCount++)
    {
        REMOVE(acInpStr[iCount],cChar);
    }
}
void fnRemChar(char *acInpStr,char cChar)
{
    char acFinalStr[MAXLEN];
    int iCount=0,iCount1=0;
    while(acInpStr[iCount]!='\0')
	{ 
if(acInpStr[iCount] != cChar)
        {
            printf("\n %c",acInpStr[iCount]);
            acFinalStr[iCount1]=acInpStr[iCount];
            iCount1++;
        }
        iCount++;
    }
    printf("\n %s\n",acFinalStr);
}
gerard4143 371 Nearly a Posting Maven

Hi
i'm trying to compile this code, but getting warning. need some help to understand what I'm doing wrong.

void printGraph(FILE *out, GraphRef G){

out = fopen (out, "w");
if( out==NULL ){
printf("Unable to open file %s for writing\n", out);
exit(1);
}
}

warning: passing arg 1 of `fopen' from incompatible pointer type

fopen is defined as

FILE* fopen(const char *path, const char *mode);

and you have fopen (out, "w"); where out is FILE*.

gerard4143 371 Nearly a Posting Maven

I love KDE and I don't know why you guys don't like it. Is there something wrong? I used KUbuntu some times ago, and was comfortable with KDE

No KDE is O.K. just different...I run KDE on my Slackware box

gerard4143 371 Nearly a Posting Maven

This function returns the address of the local variable str


Oook!! Now that makes a lot of sense, thank you. That's why it only printed the first char. Grrr i should have known.

Mental note: next time give more credit to debug's warnings.

I'm not sure which compiler your using but you should engage your warnings...i.e. gcc has a switch setting -Wall which is "warn all" and it picked up this problem in the compile stage..

gerard4143 371 Nearly a Posting Maven

This function returns the address of the local variable str

char * leer()
{
    char str[LONG], *p;
    int c;
    p = str;

    while((c = getchar()) != EOF)
    {
        if(c == '\n')
        {
            *p = 0;
            break;
        }
        *p = c;
        printf("p = %p, *p = c = %c\n", p, *p);
        p++;
    }
    return str;
}
gerard4143 371 Nearly a Posting Maven

Or this one which is a little more exotic - the language lawyers should love this one

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

void Test(char **cptr);

int main()
{
	char *str;
	Test(&str);
	fputs(str, stdout);
	free(str);
	return(0);
}

void Test(char **cptr)
{
	int val = 0;

	printf("How many characters do you want to enter->");
	scanf("%d", &val);
	getc(stdin);

	*cptr = (char*) malloc(val * sizeof(char));

	printf("Enter your text: (DO NOT INCLUDE SPACES)->");
	fgets(*cptr, val, stdin);
}
gerard4143 371 Nearly a Posting Maven

I have this much modified example that you could use for an example:

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

char* Test();

int main()
{
	char *str;
	str = Test();
	fputs(str, stdout);

	return(0);
}

char* Test()
{
	int val = 0;
	char *s;

	printf("How many characters do you want to enter->");
	scanf("%d", &val);
	getc(stdin);

	s = (char*) malloc(val * sizeof(char));

	printf("Enter your text: (DO NOT INCLUDE SPACES)->");
	fgets(s, val, stdin);

	return s;
}
gerard4143 371 Nearly a Posting Maven

Hello, i have problem at address:

0x0040E0D6 mov eax,dword ptr [ecx]

the solution would be to place an instruction to check if ecx is 0 and finishing this function, but how to do this?

Thx!

I would investigate the compare opcode and jump equal, jump not equal opcodes

Try this link:
http://www.amd.com/us-en/Processors/DevelopWithAMD/0,,30_2252_875_7044,00.html

manual 3 General-Purpose and System Instructions

gerard4143 371 Nearly a Posting Maven

In an assignment for class we have to ask the user how many characters they'd like to enter and then read the characters into an array of that size. I've had problems with calling a function to do this. I will also be passing this array to other functions, so I'm not sure if anything has to be modified either.

This is what I've done so far

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

void Test(char, int);

int main()
{
    char *text;
    int i, size, *sizeptr;
    sizeptr = &size;
    Test(text, size);
    for(i = 0; i < size; i++)
    {
        putchar(text[i]);
    }
    system("PAUSE");
    return(0);
}

void Test(char *text, int *sizeptr)
{
    int i;
    printf("How many characters do you want to enter?\t");
    scanf("%d", sizeptr);
    text = (char*) malloc(*sizeptr * sizeof(char));
    memset(text, 0, *sizeptr);
    printf("Enter your text: (DO NOT INCLUDE SPACES)\n");
    scanf("%s", text);
}

Right away I see some problems

void Test(char, int);

void Test(char *text, int *sizeptr)

gerard4143 371 Nearly a Posting Maven

Try defining your string "instruction" like below...
Also if you have errors in the future could you post them

/* Libraries */
#include <stdio.h>
#include <string.h>

char instruction[] = "add  h'13', 4";//not a constant now

/* Main Function */
int main()
{
	/* Declarations */
    
    char *action;
    char *number;
    char *number2;
    
    printf("%s \n",instruction);

// The run time error occurs here

    action = strtok ( instruction, " " );
   number = strtok ( NULL, " ' " );
number2 = strtok ( NULL, "," );

	printf("%s \n %s \n %s \n", action, number, number2);

	system("PAUSE");
	return 0;
}
gerard4143 371 Nearly a Posting Maven

Try this link...it has it all broken down

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

Aia commented: Good link +7
gerard4143 371 Nearly a Posting Maven

Here's a simple one:

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

int main(int argc, char**argv)
{
	fprintf(stdout, "ans->%u\n", 0xe5f6b7);
	exit(EXIT_SUCCESS);
}
gerard4143 371 Nearly a Posting Maven

Thanks again
I understood what happens,
but is there any solution for my while-loop ?

I can't see it anymore not to work.

A very simple solution would be to read your character and then read the newline character into a dumby variable like

char ch, extrach;

fputs("enter a character->", stdout);
ch = fgetc(stdin);
extrach = fgetc(stdin);

If you read your characters like above then your loop will work...

gerard4143 371 Nearly a Posting Maven

I am trying to write all from the begining.
So I need your help.

#include<stdio.h>

main()
{
 	char choice = '?' ;
 
	while( (choice!='D') && (choice!='K') && (choice!='T') )
	{	
		printf("Choice :");	
		choice = getchar();
		choice = toupper(choice);
	}
 }

When I press D,K, T or even 'enter' , all is ok.
When I press another letter , for example R
I take twro times 'Choice: Choice ' .

Any ideas

Try looking at this simple version of what your doing

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

int main()
{
	char mych = 0;
 	fputs("enter a character->", stdout);
	
	mych = fgetc(stdin);

	fprintf(stdout, "mych->%c, %u\n", mych, mych);

	mych = fgetc(stdin);
 	
	fprintf(stdout, "mych->%c, %u\n", mych, mych);

	exit(EXIT_SUCCESS);
 }

You'll notice you entered one character but you can retrieve two...One is the character you entered plus the character for the newline. If you want to try an experiment try adding another

mych = fgetc(stdin);

to the above program...you'll find that the third mych = fgetc(stdin); waits for you to enter another character. I guess what this is trying to prove is - you have to get rid of the additional character before you loop again...

gerard4143 371 Nearly a Posting Maven

I added a fprintf function in your code...run and check the values of choice..

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


void user()
{

	char str[15];
	int i=0;
	
	do{
		printf("\nPrint str.\n");
		fgets(str,15,stdin);
		i = strlen(str);
	}while(i>15);
}

void menu()
{
	printf("Press :\n"); 
	printf("0. \n");
	printf("1. \n");
	printf("2. \n");
}

int get_choice()
{
 int choice = 0 ;
 const char* const valid_choices = "012" ;

 do
 {
   fputs( "Your choice : ", stdout ) ;
   fflush( stdin ) ;
   choice = toupper( fgetc( stdin ) ) ;
   fgetc( stdin ) ;

	fprintf(stdout, "choice->%d, %c\n", choice, choice);//check the value of choice

   if( strchr(valid_choices, choice) == NULL )
   {
     fputs("Invalid option.\n", stdout);
     choice = 0 ;
   }
 } while( choice == 0 ) ;

 return choice ;
}



main()
{
	int choice=0;

	do
   	{
             menu() ;
      	     choice = get_choice() ;

      		switch(choice)
     		 {
          		case 0: user();
			   		 break ;
          		case 1: break ;
          		case 2: break;
		}
     		
	 }while(choice != 2);
  
}
gerard4143 371 Nearly a Posting Maven

What is this program supposed to do? If you could give us an example...say

When I run this program and I'm prompted for this and I press this - this happens, when in fact this should happen...I hope this makes sense

gerard4143 371 Nearly a Posting Maven

when i click on the link its closing all my opened browsers.

whats that ?

if you have some idea of gstreamer plz let me know the correct place where i get that .
i have already given you my sys info.

becuse i have downloaed the gstreamer files, but its not installing.

I just tried the link and its works fine..If you go to google and query www.fluendo.com you should be able to find gstreamer(its with the MP3 section)

gerard4143 371 Nearly a Posting Maven

Hi,

i like to know what are the different systems that have gstreamer built in, or systems which allows gstreamer to be installed.

I also like to know what this below lines specifies:
I found this in my shell of proc/version file
Linux Version 2.6.9-5.Elsm gcc version 3.4.3 20041212 (red hat 3.4.3-9.El4) #1 smp wed jan 5 19:30:39 EST 2005.

can i install gstreamer on my system.

Thanks.

Also the last line is the output of uname. The translations is:
Linux Version 2.6.9-5 - kernel version
gcc version 3.4.3 - GCC compiler version
red hat 3.4.3-9.El4 - Linux Flavour

If you want to generate this info - open a terminal and type uname -a

gerard4143 371 Nearly a Posting Maven

"%u" is for unsigned in, "%lu" is unsigned long int, two different int sizes.

Yeah I know the last line was a pun

gerard4143 371 Nearly a Posting Maven

It will depend on the version of the compiler that is used. Declaring objects in the middle of a block like we can do with c++ is only supported by versions of C compiler that support C99 standards.

AD is right most/all C code has declarations at the beginning of the blocks by convention or by requirement...

gerard4143 371 Nearly a Posting Maven

I just copied and compiled your code without issue on a Linux box using

gcc filename.c -o filename

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

I wrote this very small program that works fine until I remove the comments for the fprintf function.

Basically the program will prompt the user for a numeric value, when the user guesses right(1234) the program exits. When I remove the comments the program never exits...Does anyone have any idea why? I'm completely lost as to why it would behave like this...maybe its my compiler - gcc 4.4.1

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

unsigned long testval = 1234;

void* foundit(void)
{
	fputs("found it!\n", stdout);
	return (void*)0;
}

void* tryit(void)
{
	unsigned long val;

	fputs("enter a value/guess->", stdout);
	fscanf(stdin, "%u", &val);
	
	if (val == testval)
	{
		return (void*)&foundit;
	}
	else
	{
		return (void*)&tryit;
	}
}

int main(int argc, char**argv)
{
	void *addr = (void*)&tryit;

	//fprintf(stdout, "ans->%u\n", 1);	//remove comments and program runs 
							//but fails to exit with correct value
	while ((addr = ((void*(*)(void))addr)()))
	{}
	exit(EXIT_SUCCESS);
}

Found the problem...well it'll compile and run as intended with this change. It was this line.

fscanf(stdin, "%u", &val);

When I changed it to it ran as intended

fscanf(stdin, "%lu", &val);

I'm still not 100% sure why this is happening...maybe its the common extensions I choose to associate with....

gerard4143 371 Nearly a Posting Maven

When I do this:

la $a1, 9($t1)

the code works, but when I do this:

marker: .word 9
la $a1, marker($t1)

The code doesn't work.... I don't understand why....?

I'm not familiar with the above syntax so this is a guess....when you place 9 into the label marker you place into memory so the second set of instructions requires a memory call while the first, 9 can be made into part of the instruction or immediate so no memory call to retrieve it...Like I said this is a guess because I'm not familiar with this syntax....

gerard4143 371 Nearly a Posting Maven

As part of my program, I have defined and initialized a structure. But when I compile it, gcc gives me the following error on all the initialization " initializer element is not constant". Anyone know why this is the case?

struct RECORD 
{
	char* username;
	char* password;
	char* type;
	struct RECORD *next;
};

struct RECORD *head=(struct RECORD*)malloc(sizeof(struct RECORD));
struct RECORD *temp=(struct RECORD*)malloc(sizeof(struct RECORD));
struct RECORD *linktemp=(struct RECORD*)malloc(sizeof(struct RECORD));
struct RECORD *pos=(struct RECORD*)malloc(sizeof(struct RECORD));

I get an error on code lines 9-12.

I tried this and it compiled no problems

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

struct RECORD 
{
	char* username;
	char* password;
	char* type;
	struct RECORD *next;
};


int main(int argc, char**argv)
{
	struct RECORD *head=(struct RECORD*)malloc(sizeof(struct RECORD));
	struct RECORD *temp=(struct RECORD*)malloc(sizeof(struct RECORD));
	struct RECORD *linktemp=(struct RECORD*)malloc(sizeof(struct RECORD));
	struct RECORD *pos=(struct RECORD*)malloc(sizeof(struct RECORD));
	

	exit(EXIT_SUCCESS);
}
gerard4143 371 Nearly a Posting Maven

Are you posting your entire homework assignment?

gerard4143 371 Nearly a Posting Maven

This is a very simple version of how it might work

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

char ch[100];

int main(int argc, char**argv)
{
	FILE *fd;
	if (!(fd = fopen("testfile", "r")))
	{
		fputs("could not open testfile!\n", stderr);
		exit(EXIT_FAILURE);
	}

	fscanf(fd, "%s", ch);
	fprintf(stdout, "string->%s\n", ch);
	fscanf(fd, "%s", ch);
	fprintf(stdout, "string->%s\n", ch);
	fscanf(fd, "%s", ch);
	fprintf(stdout, "string->%s\n", ch);
	fscanf(fd, "%s", ch);
	fprintf(stdout, "string->%s\n", ch);

	fclose(fd);

	exit(EXIT_FAILURE);
}

the data file

this,is,line,one
this,is,line,two
this,is,line,three
this,is,line,four
gerard4143 371 Nearly a Posting Maven

So what your saying is the fields are comma separated and the records are newline separated?

gerard4143 371 Nearly a Posting Maven

Why not just turn off the warning? :icon_rolleyes:

Who's turning off the warning....I'm coercing the data to fit the function. Its done all the time

gerard4143 371 Nearly a Posting Maven

Have the code mirror what you're doing:

char *VAR1(const char *VAR2)

Also, make sure you have enough space to write into.

[edit]If he wants the warning...

why would a solution be to silence the warning with the cast?

Depends how you want to look at this....Are you the developer of the app or a developer using the app...i.e. do you have the rights to change the function then yes change it but sometimes(most times) you have to change the data to fit the function...

gerard4143 371 Nearly a Posting Maven

Try this

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

char *VAR1(char *VAR2)
{
	static char VAR3[12] = "Hello ";
	strcat(VAR3, VAR2);

	return VAR3;
}

int main(void)
{
	printf("%s", VAR1((char*)"World!")); // Hello World!

	return 0;
}
gerard4143 371 Nearly a Posting Maven

I don't really see your point....You go out of your way to note this issue and then your quotes verify that indeed it is a very common extension to the language....Is your point that is not 100% the standard? I can live with that, I'm very comfortable living in the common extensions of the language...

gerard4143 371 Nearly a Posting Maven

Originally Posted by C99 Section 6.3.2.3

1 A pointer to void may be converted to or from a pointer to any incomplete or object
type. A pointer to any incomplete or object type may be converted to a pointer to void
and back again; the result shall compare equal to the original pointer.

Maybe I'm having problems with this statement
"the result shall compare equal to the original pointer"

Then again I never was a language lawyer

gerard4143 371 Nearly a Posting Maven

>No the complier had no problems casting a void pointer to a function..should it?
It might. Technically void* and functions pointers are incompatible and converting between them is undefined behavior.

Could you give an example....

gerard4143 371 Nearly a Posting Maven

You could try something like below...I generally don't like the solution but it works for some situations

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

#define t "     "

int main(int argc, char**argv)
{		
	fprintf(stdout, "this\tis\ta\ttest", stdout);	
	exit(EXIT_SUCCESS);
}
gerard4143 371 Nearly a Posting Maven

Well I tried compiling the code on GCC 4.3.2 and it worked. I think GCC 4.4.1 may be in need of an update...Thanks again Ancient Dragon

So to recap:

the code will not work correctly on GCC 4.4.1
but it will work correctly on GCC 4.3.2, GCC 3.4.5 and vc++ 2008 express

gerard4143 371 Nearly a Posting Maven

I have this old piping program example...maybe you'll get something out of it.

Usage ./filename ps wc

will pipe the output of ps into wc

#include <unistd.h>

enum PIPES {READ, WRITE};

int main(int argc, char**argv)
{
	if (argv[2])
	{
		int hpipe[2];
		pipe(hpipe);

		if (fork())
		{
			close (hpipe[WRITE]);
			dup2 (hpipe[READ], 0);
			close (hpipe[READ]);
			execlp (argv[2],argv[2],NULL);
		}
		else
		{
			close (hpipe[READ]);
			dup2 (hpipe[WRITE], 1);
			close (hpipe[WRITE]);
			execlp (argv[1],argv[1],NULL);
		}
	}
	return 0;
}
gerard4143 371 Nearly a Posting Maven

Worked fine for me using vc++ 2008 express

Humph...That means I'm going have to walk through some assembler and find out why removing the comments from this line

fprintf(stdout, "ans->%u\n", 1);

causes the program to behave differently...well besides printing 1 to the display..

Thanks for trying the program Ancient Dragon

gerard4143 371 Nearly a Posting Maven

>>while ((addr = ((void*(*)(void))addr)())

Didn't your compiler produce an error or warning on that line?? tryit() does not return a value, yet in the above addr is being assigned the return value of tryint(). You can't have it both ways. try this: while( addr() )

No the complier had no problems casting a void pointer to a function..should it?
And for tryit() the if statement assures that the function returns a value..

But that isn't the problem...The problem is when I remove the comments from this line

//fprintf(stdout, "ans->%u\n", 1);

The program fails to exit correctly...Note the program works as intended while the comments are there...

gerard4143 371 Nearly a Posting Maven

I wrote this very small program that works fine until I remove the comments for the fprintf function.

Basically the program will prompt the user for a numeric value, when the user guesses right(1234) the program exits. When I remove the comments the program never exits...Does anyone have any idea why? I'm completely lost as to why it would behave like this...maybe its my compiler - gcc 4.4.1

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

unsigned long testval = 1234;

void* foundit(void)
{
	fputs("found it!\n", stdout);
	return (void*)0;
}

void* tryit(void)
{
	unsigned long val;

	fputs("enter a value/guess->", stdout);
	fscanf(stdin, "%u", &val);
	
	if (val == testval)
	{
		return (void*)&foundit;
	}
	else
	{
		return (void*)&tryit;
	}
}

int main(int argc, char**argv)
{
	void *addr = (void*)&tryit;

	//fprintf(stdout, "ans->%u\n", 1);	//remove comments and program runs 
							//but fails to exit with correct value
	while ((addr = ((void*(*)(void))addr)()))
	{}
	exit(EXIT_SUCCESS);
}
gerard4143 371 Nearly a Posting Maven

Here's what I mean
1010101010101111
First twelve is 101010101010
Shift left twelve gives
1111000000000000
Shift right twelve then gives
0000000000001111

O.K. what I meant was the opposite to what you have here...either way your method works..Thanks

gerard4143 371 Nearly a Posting Maven

Ok so I make my masks

short m1, m2, m3, m4;

m1 = 0xF000;
m2 = 0x0F00;
m2 = 0x00F0;
m3 = 0x000F;

and then I test my masks

printf("%hd %hd %hd %hd\n", m1, m2, m3, m4);

when I test it the values come out as

-4096 240 15 0

which is equal to

0xF000
0x00F0
0x000F
0x0000

which is messing up my checksum program when I try to apply the masks. :-\

Any advice?

I tried initializing the values like this and it worked

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

int main(int argc, char**argv)
{

short m1 = 0xf000, m2 = 0x0f00, m3 = 0x00f0, m4 = 0x000f;

printf("%hd %hd %hd %hd\n", m1, m2, m3, m4);

exit(EXIT_SUCCESS);
}

What are you using for a compiler?

gerard4143 371 Nearly a Posting Maven

I'd just do a bitwise shift left 12 then a bitwise shift right 12

Don't you mean the other way around? Maybe I have a different meaning for first 12