Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

pointer to string error

Status
Not open for further replies.

syedshan

Advanced Member level 1
Joined
Feb 27, 2012
Messages
463
Helped
27
Reputation
54
Reaction score
26
Trophy points
1,308
Location
Jeonju, South Korea
Activity points
5,134
Hello all,

I am completely new to the practical programming of C

I have done C-programming during my undergraduate 2 years ago, now that I have to reuse it in one of my program I have restarted its revision...
I have problem with the Pointers to C, as we know that declaring char *p; would create a string pointer.

Hence I typed in the following code and compile it using Visual studio 2010

Code:
#include <conio.h>
#include <stdio.h>
#include <iostream>

int main(void)
{
	char *pta; 
	puts("Enter name : ");
	scanf("%s",pta);
//	gets(name); // I also tried this thing with gets() as well	
}

I am having following error (please see the image as well) "The Variable pta is being used without initialization"
 

Yaa.... you need to allocate some memory to the pointer

try this -
Code:
#include <conio.h>
#include <stdio.h>
#include <iostream>

int main(void)
{
	char *pta; 
         pta = (char *) malloc(100*sizeof(char));
	puts("Enter name : ");
	scanf("%s",pta);
//	gets(name); // I also tried this thing with gets() as well	
}


Good Luck
 
Hey great...

Thanks for help.
It works...

Pardon me if I can ask... malloc(100*sizeof(char)) would aqcuire 100 x 1 Byte memory for us, i.e 100 Byte memory
 

Yes.... you are right... as the char is 1 byte so when you say malloc(100*sizeof(char)) would aqcuire 100 x 1 Byte....

Good Luck
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top