gerard4143 371 Nearly a Posting Maven

>In my case, I obtain errors (undefined reference to `myVar') when I use extern in "global.h."
Are you forgetting the definition? I added a globals.c file that forces an absolute definition for myVar. If you don't have that definition somewhere, the linker won't be able to reference the object.

>This may not be 100% but I always though of global
>and external variables as indicators to the linker

Technically there's no such thing as a global variable. What people usually mean by "global" is an object with file scope and external linkage which can be made visible in other scopes using an external declaration.

I'm not arguing with you but global variables must be an accepted misconception..
Try gooling global variables in C

gerard4143 371 Nearly a Posting Maven

This may not be 100% but I always though of global and external variables as indicators to the linker such that:

global variable is available out side of the file its defined in.
external variable is defined out side of the file its used in.

gerard4143 371 Nearly a Posting Maven

I never done a palindrome routine before but I would:

1. take original string and create new string removing all characters like spaces, tabs, punctuation.

2. I would take the new string and check each character with either toupper/tolower
therefore nullifying case.

These are only suggestions because like I said I never create a palindrome routine.

gerard4143 371 Nearly a Posting Maven

Number one, I have to ask, how strict is your definition of palindrome?

Would you consider this one - Madam, I'm Adam

Where punctuation, case and spaces are ignored.

gerard4143 371 Nearly a Posting Maven

Try the function strcmp or strncmp.

gerard4143 371 Nearly a Posting Maven

hi..pls help me with this ...when i run this c program i get in result segmentation fault message (i run in ubuntu terminal):

#include<stdio.h>
#include<utmp.h>
int main()  {
       char *s,*c;
       struct utmp *u;
       int i;
       c=getlogin();
       setutent();
       u=getutent();
       while(u!=NULL)  {
          if(u->ut_type==7 && strcmp(u->ut_user,c)==0) {
               printf("%-12s",u->ut_user);
               printf("%-9s",u->ut_line);
               s=ctime(&u->ut_time);
               for(i=4;i<16;i++)
               printf("%c",s[i]);
               printf("(%s",u->ut_host);
               printf(") ");
          }
       u=getutent();
       }
}

and when compile i get warnings:
gcc -o who who.c
who.c: In function ‘main’:
who.c:7: warning: assignment makes pointer from integer without a cast
who.c:14: warning: assignment makes pointer from integer without a cast

i must mention that programs must return the same as the command who (linux)
thx...and sry for bad english

I quickly look at your program and this works(I would clean up the hack)

#include<stdio.h>
#include<utmp.h>
#include <unistd.h>
#include <time.h>

int main()  {
       char *s,*c;
       struct utmp *u;
       int i;
       c=getlogin();
       setutent();
       u=getutent();
       while(u!=NULL)  {
          if(u->ut_type==7 && strcmp(u->ut_user,c)==0) {
               printf("%-12s",u->ut_user);
               printf("%-9s",u->ut_line);
               s=ctime((const time_t*)&u->ut_time);	//this was a quick hack
							//you could probably do it better
               for(i=4;i<16;i++)
               printf("%c",s[i]);
               printf("(%s",u->ut_host);
               printf(") ");
          }
       u=getutent();
       }
}

Also main should return 0;
and strcmp should include <string.h>

gerard4143 371 Nearly a Posting Maven

Mmm... Thanks Gerard, if I'm thinking of the right thing (vi enhanced) - mmm... is it possible to I be able to set breakpoints, step over and step into? I think in the least I'll need that.

That would be a debugger your talking about...If you expect your IDE to come fully featured then it won't be lightweight....Can VIM use a debugger? I really don't know because I never tried...

I would look into Code blocks, Gedit, Kwrite, Kdevelop, bluefish...or just Google Linux IDE since most are ported to Windows.

gerard4143 371 Nearly a Posting Maven

If you want simple and complex then try VIM...

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

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

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

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

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

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

Which run time error would that be?

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

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

That would probably depend on how its initiated...

You really should consult the Intel/AMD manuals..they have very good explanations of each opcode....

gerard4143 371 Nearly a Posting Maven

Hello,
I was just wondering if the hlt instruction would produce a blinking cursor at the command line until enter is pressed or if its use is not noticeable to the user. Google wasn't too helpful for the specifics of the instruction. Thanks!

That would probably depend on how its initiated...

gerard4143 371 Nearly a Posting Maven

I have a question:

#include <stdio.h>

char * chstrswithf(char * a)
{
while(*a!='\0')
{
if(*a=='s')
*a='f';
a++;
}
return a;
}


int main(void)
{
	char string[]="this is a string";
	chstrswithf(string);
	printf("%s \n",string);
	return 0;
}

the code above is ok for running.
but when I replace the char string[]="this is a string"; with char* string="this is a string";, the error occurs. What's the reason?

char *str is read only

gerard4143 371 Nearly a Posting Maven

I have no idea why your launching above your tank but you really should be using pygame to handle the graphics...

If you can't find any answers then build a projectile log that will log every position the shell has. With this you have a very good diagnostic tool plus you'll be able to tweak your physics...

gerard4143 371 Nearly a Posting Maven

Just curious to what you think an unsigned char is but zeros and ones

try compiling this

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

unsigned char xorBufferTemp[8];
unsigned char bufferHexas1[8];
unsigned char bufferHexas2[8];

int main(int argc, char**argv)
{
	bufferHexas1[0] = 15;
	bufferHexas2[0] = 1;
	xorBufferTemp[0] = bufferHexas1[0] ^ bufferHexas2[0];

	fprintf(stdout, "ans->%u\n", xorBufferTemp[0]);

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

So saying "cmp bx,1" would check if there was one argument passed? I tried taking the stack all the way up to 28, and got the same results. "It did'nt work" as my message. I do really appreciate your help by the way, is there a way for me to +rep you?

cmp bx, 1 should work...at least its an easy way to see if your checking values on the stack...If you get a true for cmp bx, 1 try changing it to cmp bx, 3 and pass three arguments and see if it still works..If it does then try dereferencing the value ahead of it to see if its your string...Good luck

gerard4143 371 Nearly a Posting Maven

I would try experimenting with this line

mov     bx,[bp+4]

Try values like
mov bx,[bp+8]
mov bx,[bp+12]

Just keep working your way up the stack...

Note the first value on the stack is the number of arguments

Also the command line argument isn't saved on the stack...a pointer to the command line argument is saved on the stack.

gerard4143 371 Nearly a Posting Maven

Did you try Googling "Windows XP 16 bit programs"

http://pcs.suite101.com/article.cfm/windows_xp_compatability_mode

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

Thanks. I would not know how to test this on windows as I have never used Linux, but I appreciate your time to reply.

Windows will pass the command line arguments via the stack so you'll get then by taking an offset of the stack pointer. In 16 bit programming I believe that is accomplished with ss:sp

where ss is the segment register and sp is the stack pointer together they will give you the base of the stack

gerard4143 371 Nearly a Posting Maven

I know how to do it in 64 bit assembly using Linux's as. You just take the offset of the rsp register.i.e

16(%rsp) will get the first command-line argument

In 32 bit Linux's as

8(%esp) to get the first command-line argument

...For 16 bit...I don't think Linux supports 16 bit exe's so I never had the opportunity to try but if it did it would probably be an offset of the ss:sp registers...Hope this helps

gerard4143 371 Nearly a Posting Maven

If you want to see how other language's handle function overloading, try Googling "name mangling" and you'll see the compiler just renames or mangles the said functions names according to some scheme based on the parameter types...

gerard4143 371 Nearly a Posting Maven

I notice you have the binding to the configure event rem'd out. Why?

Wait are you talking about the desktop width and height?

Try this link

http://www-acc.kek.jp/WWW-ACC-exp/KEKB/Control/Activity/Python/TkIntro/tkmanual/winfo.html

gerard4143 371 Nearly a Posting Maven

Hi,

I am doing network programming in C. I want to send Hexadecimal data between client and server. But stuck how C handles Hexadecimal values? I would like to put and example.

I am having a variable ACK_CODE 0*81. Now want to send it. Since the send call can only receive String data then how we can send the above code in send()? Also how to retrieve that back into Hexadecimal from String in recv() call?

Can anyone help me in this regard?

Thanks

Shahab

The send function accepts a const void *buf in Linux so I expect it accepts something similar in Windows. Just cast the data to const void* and pass along the size

gerard4143 371 Nearly a Posting Maven

Not sure what NASM16 is? Is this 16 bit programming?

gerard4143 371 Nearly a Posting Maven

C does not have pass by reference. It can only be faked passing pointers by value and using indirection them to get the original object.

Just curious, what do you think C++ does when it passes by reference. You said pass by reference doesn't copy the value or the address of the data. So how does the function locate the values or data?

I think you'll find its just a special case pointer that's handled by the compiler. I could be wrong...C++ isn't really my thing.

gerard4143 371 Nearly a Posting Maven

Plus scanf("%c", operation2);

should be

scanf("%c", &operation2);

gerard4143 371 Nearly a Posting Maven

I know my problem is within the SWITCH CASE!!

You might get a faster reply if you told us what's wrong..

gerard4143 371 Nearly a Posting Maven

Is pass by value and call by reference the same? I mean i know theres no call by reference in C but there is similarity int he output of the two isn't it?

why do we use call by value and pass by value? what are its uses?

Do you mean a C++ reference? Because a C++ reference is just a special case pointer..

Your second question...we use pass by value to protect the integrity of the original value

gerard4143 371 Nearly a Posting Maven

Did it mention which line?

gerard4143 371 Nearly a Posting Maven

C can be transfered to different machines because the standard library abstracts away may of these details...i.e. The language is the same but each machine gets its own standard library to handle these details. So when you transfer source code between machines and recompile the standard library makes sure everything lines up for that machine...

gerard4143 371 Nearly a Posting Maven

Nice program....Why did you post it?

gerard4143 371 Nearly a Posting Maven

Not sure what your asking?

Do you mean you want to create:

1. a thread which exists in the current process
2. a new process which exists independently

gerard4143 371 Nearly a Posting Maven

This works..maybe you can figure out why

#include<stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include<unistd.h>
#include<string.h>

struct Student
{
  char name[21];
  char id[11];
  char DOB[9];
  char gender[2];
  char status[2];
};

struct Student myArr[5];//An array of Struct Student  
int main()
{
  int x, y, z;
	char dumb[1];
  char newline[2] = { "\n" };
  char sep[5] = { "    " };
  char buf1[] = { "Please enter the name of the student's:" };
  char buf2[] = { "Please enter the student's id:" };
  char buf3[] = { "Please enter the student's DOB:" };
  char buf4[] = { "Please enter the student's gender:" };
  char buf5[] = { "Please enter the student's marital status:" };

  //O_CREAT requires a third argument the mode which specifies the access permission bits
  //S_IRWXU indicates that the user has read, write and execute permissions
  x = open( "/home/user/Desktop/Labsheets/Labsheet4/input.dat", O_RDWR | O_CREAT | O_TRUNC, S_IRWXU );
  //fd 0 is standard input and 1 is standard output
  //will read from standard input and place data in the buffer
  //read return number of bytes read
  int i;
  for( i = 0; i < 5; i++ )
  {
    write( 1, buf1, strlen(buf1) );
    read( 0, myArr[i].name, 20 );//read from standard input and place data in buffer
    write( 1, buf2, strlen(buf2) );;
    read( 0, myArr[i].id, 10 );
    write( 1, buf3, strlen(buf3) );
    read( 0, myArr[i].DOB, 9 );
    write( 1, buf4, strlen(buf4) );
    read( 0, myArr[i].gender, 1 );
	read( 0, dumb, 1 );
    write( 1, buf5, strlen(buf5) );
    read( 0, myArr[i].status, 1 ); …
gerard4143 371 Nearly a Posting Maven

did you try putting the full path with your cd