Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pointer help

Status
Not open for further replies.

ecannizzo

Programmer
Sep 19, 2000
213
US
I am using the code below and when I do a printf on my variable which gets filled by a pointer variable, I get all the weird stuff after my data. It looks like lines and a little L. Can someone help?

#include "stdafx.h"
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <conio.h>


void main(void)
{
void inputch(char *);
char partid[7];

printf(&quot;What is the Part ID? &quot;);

inputch(partid);

printf(&quot;\nValidation done! Part ID is %s\n&quot;, partid);

}


void inputch(char *pID)
{
char ch; //hold input from user
int x; //counter to keep track of number of character coming in from user

x = 0; //initialize

do {

ch = toupper(getch()); //uppercase user input

if (ch == '\b') { //equals backspace
putch('\b');
putch(' ');
putch('\b');
x--;
}
else if ((ch != '\0') && (x < 2)) { //doesn't equal null
if (isalpha(ch)) { //if its a character
putch(ch); //write it to the screen
pID[x] = ch; //put character in pointer variable
x = x + 1;
}
}
else if ((ch != '\0') && ((x >= 2) && (x < 6))) {
if (isdigit(ch)) {
putch(ch); //write it to the screen
pID[x] = ch; //put number in pointer variable
x = x + 1;
}
}

} while (ch != '\r'); //carraige return

}

This is all the code so you can test it in the compiler.
Thanks!
 
I figured it out. Thanks anyway!! I needed to use *pID
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top