Solving Pointer in C Language: Placing ptr on name1,2,3

In summary, the conversation discusses a problem with pointers in the C language. The person is struggling to correctly place pointers on different names and has been working on it for over 24 hours. They have tried using strcmp to compare names, but it did not work for the last name. The other person suggests that the problem may be with the array of characters and asks for the code to better understand the issue. The person with the problem expresses frustration and thanks those who have tried to help.
  • #1
pouchito
20
0
pointers ...C language

I need your help:

name1 < name 2 > name 3

I m writing a problem that place:
a pointer on name 1
a pointer on name 2
a pointer on name 3

I have been working on it more than 24 hours but in vain :cry:

what i did is strcmp with < if it is place ptr 1 (it works)
then
strcmp if there is sthg after the < place ptr 2 (it works)

BUT The same procedure didn't work for the latest name PLEASE I SPEND hundreds of hour on writing my program and i m still stuck in many parts...can u help me solving this part

thanks
 
Technology news on Phys.org
  • #2
A name, assuming that you made it an array of characters, will always be a pointer. Make sure you understand that completely. It would help immensely if you posted your code so I can see exactly what you're doing incorrectly.
 
  • #3
not clear

I don't understand your problem specification. The number one rule of computer science is that the problem specification must be spelled out clearly and non-ambiguous. You will find out this true for small assignments, and real projects.
 
  • #4
my problem is solved !

Thanks all of you
 

Related to Solving Pointer in C Language: Placing ptr on name1,2,3

1. How do I declare and initialize a pointer in C?

To declare and initialize a pointer in C, you can use the following syntax: int *ptr = NULL; This creates a pointer named "ptr" that points to nothing. You can also initialize a pointer to point to a specific variable by using its address, like this: int *ptr = &variable; where "variable" is the name of the variable you want the pointer to point to.

2. How do I access the value stored at the address pointed to by a pointer?

To access the value stored at the address pointed to by a pointer, you can use the dereferencing operator, which is the asterisk symbol (*). So, if you have a pointer named "ptr" that points to a variable, you can access the value of that variable by using *ptr. This will return the value stored at the address pointed to by the pointer.

3. How do I change the value stored at the address pointed to by a pointer?

To change the value stored at the address pointed to by a pointer, you can again use the dereferencing operator (*), but this time on the left side of an assignment statement. For example, if you want to change the value of the variable pointed to by "ptr" to 10, you can use *ptr = 10; This will assign the value 10 to the variable pointed to by "ptr".

4. What is the difference between a pointer and a regular variable in C?

A pointer is a variable that stores the address of another variable. This means that a pointer can indirectly access and manipulate the value of another variable by pointing to its address. On the other hand, a regular variable stores a specific value. Pointers are useful for tasks such as passing variables by reference and dynamically allocating memory.

5. How do I avoid common errors when working with pointers in C?

One common error when working with pointers in C is forgetting to allocate memory for the pointer before using it. This can lead to unexpected behavior or program crashes. Another common error is dereferencing a null pointer, which means trying to access the value stored at an invalid address. To avoid these errors, always make sure to properly allocate memory for your pointers and check for null pointers before dereferencing them.

Similar threads

  • Programming and Computer Science
Replies
2
Views
952
  • Programming and Computer Science
Replies
7
Views
4K
  • Programming and Computer Science
Replies
18
Views
2K
  • Programming and Computer Science
3
Replies
75
Views
4K
  • Programming and Computer Science
Replies
2
Views
11K
  • Engineering and Comp Sci Homework Help
Replies
12
Views
2K
  • Programming and Computer Science
Replies
3
Views
347
  • Engineering and Comp Sci Homework Help
Replies
5
Views
2K
  • Programming and Computer Science
Replies
20
Views
3K
Back
Top