hi guys
this is my code
#include<stdio. h>
main()
{
char *p[]={"hello" ,"world" ,"Nice","show"} ;
char **p1;
}
I want to print the string "helwornics ho" by using ptr increment or
decrement.
How can I do that.
I tried to print charachter by charachter .
But for that increment ptr pointing to each charachter .
I used (**p1)++.But it is giving segmentation fault.
Plz tell the error. 14 2073
Please another thing is there is statement after
char **p1;
p1=p;
vim wrote: hi guys
this is my code #include<stdio. h> main() { char *p[]={"hello" ,"world" ,"Nice","show"} ; char **p1; } I want to print the string "helwornics ho" by using ptr increment or decrement. How can I do that. I tried to print charachter by charachter . But for that increment ptr pointing to each charachter . I used (**p1)++.But it is giving segmentation fault. Plz tell the error.
If you can't explain what exactly you want to achieve, and if you won't
post the code you tried and failed, there's little chance anyone can
help.
I guess you want to print first three characters of each element of
`p`, possibly with the first one of each being forced to lowercase. In
which case, this should do you nicely:
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
char *p[]={"hello" ,"world" ,"Nice","show"} ;
int i,j;
for (i = 0; i < (sizeof p / sizeof p[0]); ++i)
{
/* no error checking here */
for (j = 0; j < 3; ++j)
{
printf("%c", tolower(p[i][j]));
}
}
printf("\n");
return 0;
}
Be warned, I did not include checks to see whether any of the array
elements are long enough (i.e. have at least three characters).
vim wrote: Please another thing is there is statement after char **p1; p1=p;
Quote context, even when replying to own posts. Read
<http://cfaj.freeshell. org/google/>.
I have a sneaky suspicion you've been told this before (and more than
once). If you want to be taken seriously here, please follow the advice
in the link above, and also below:
<http://www.clc-wiki.net/wiki/Introduction_to _comp.lang.c>
Vladimir Oka wrote: vim wrote: hi guys
this is my code #include<stdio. h> main() { char *p[]={"hello" ,"world" ,"Nice","show"} ; char **p1; } I want to print the string "helwornics ho" by using ptr increment or decrement. How can I do that. I tried to print charachter by charachter . But for that increment ptr pointing to each charachter . I used (**p1)++.But it is giving segmentation fault. Plz tell the error. If you can't explain what exactly you want to achieve, and if you won't post the code you tried and failed, there's little chance anyone can help.
I guess you want to print first three characters of each element of `p`, possibly with the first one of each being forced to lowercase. In which case, this should do you nicely:
#include <stdio.h> #include <stdlib.h>
Sorry, it should have been:
#include <stdio.h>
#include <ctype.h>
int main(void) { char *p[]={"hello" ,"world" ,"Nice","show"} ; int i,j;
for (i = 0; i < (sizeof p / sizeof p[0]); ++i) { /* no error checking here */ for (j = 0; j < 3; ++j) { printf("%c", tolower(p[i][j])); } } printf("\n");
return 0; }
Be warned, I did not include checks to see whether any of the array elements are long enough (i.e. have at least three characters).
Vladimir Oka wrote: vim wrote: hi guys
this is my code #include<stdio. h> main() { char *p[]={"hello" ,"world" ,"Nice","show"} ; char **p1; } I want to print the string "helwornics ho" by using ptr increment or decrement. How can I do that.
I guess you want to print first three characters of each element of `p`, possibly with the first one of each being forced to lowercase. In which case, this should do you nicely:
#include <stdio.h> #include <stdlib.h>
I think you mean "ctype" instead of "stdlib" int main(void) { char *p[]={"hello" ,"world" ,"Nice","show"} ; int i,j;
for (i = 0; i < (sizeof p / sizeof p[0]); ++i) { /* no error checking here */ for (j = 0; j < 3; ++j) { printf("%c", tolower(p[i][j])); } } printf("\n");
return 0; }
Be warned, I did not include checks to see whether any of the array elements are long enough (i.e. have at least three characters).
It could be a little more pointer incremental.
/* BEGIN new.c */
#include <stdio.h>
#include <ctype.h>
#define THREE 3
int main(void)
{
char *p[] = {"hello" ,"world" ,"Nice","show"} ;
char **p1;
int x;
for (p1 = p; *p1 != p[sizeof p / sizeof *p]; ++p1) {
for (x = 0; x != THREE; ++x) {
putchar(tolower (*(*p1)++));
}
}
putchar('\n');
return 0;
}
/* END new.c */
--
pete
On 2006-05-18, vim <vg*****@gmail. com> wrote: hi guys
You are already annoying me with your lack of capitals.
this is my code
One sec, here's a cleaned up version:
#include <stdio.h>
int main(void)
{
char *p[]={"hello" ,"world" ,"Nice","show"} ;
char **p1;
p1 = p; /* As per your most recent post */
/* You should have posted context */
/* Actual code here */
return 0;
}
I want to print the string "helwornics ho" by using ptr increment or decrement.
What is "ptr"? I don't see it in your code.
How can I do that. I tried to print charachter by charachter .
Easier to set the fourth character of each string to '\0' and then
printf ("%s", p[i]), no?
But for that increment ptr pointing to each charachter . I used (**p1)++.But it is giving segmentation fault.
**p1 points to the letter h, which is part of a string literal. You
don't need to increment that, and if you could you'd end up with 'i'
instead of the next letter.
Use *p1++ to jump to the next word, and p1++ to jump to the next
letter. The parentheses are unnecessary.
Plz tell the error.
What does "plz" mean? That isn't in your code either.
--
Andrew Poelstra < http://www.wpsoftware.net/blog >
pete wrote: Vladimir Oka wrote: vim wrote: hi guys
I forgot to mention,
anyone who does your homework for you, isn't being your friend.
/* BEGIN new.c */ /* END new.c */
But if you ask questions, they will be answered.
--
pete
"vim" <vg*****@gmail. com> wrote in message
news:11******** **************@ j33g2000cwa.goo glegroups.com.. . Please another thing is there is statement after char **p1; p1=p;
Where is the context? I see two statements here; where is the rest?
What is your question?
--
Fred L. Kleinschmidt
Boeing Associate Technical Fellow
Technical Architect, Software Reuse Project
pete wrote: Vladimir Oka wrote: vim wrote: hi guys
this is my code #include<stdio. h> main()
<snip>
I guess you want to print first three characters of each element of `p`, possibly with the first one of each being forced to lowercase. In which case, this should do you nicely:
#include <stdio.h> #include <stdlib.h>
I think you mean "ctype" instead of "stdlib"
Yes. Thanks. (I did notice myself, as well, albeit too late).
<snip> Be warned, I did not include checks to see whether any of the array elements are long enough (i.e. have at least three characters).
It could be a little more pointer incremental.
It was deliberate. I wasn't going to do OP's homework. ;-) This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Carsten Spieß |
last post by:
Hello all,
i have a problem with a template constructor
I reduced my code to the following (compiled with gcc 2.7.2) to show
my problem:
// a base class
class Base{};
// two derived classes
|
by: Mr A |
last post by:
Hi!
I've been thinking about passing parameteras using references instead
of pointers in order to emphasize that the parameter must be an
object.
Exemple:
void func(Objec& object); //object must be an object
instead of
|
by: Bruno van Dooren |
last post by:
Hi All,
i have some (3) different weird pointer problems that have me stumped. i
suspect that the compiler behavior is correct because gcc shows the same
results.
----------------------------------------------
//example 1:
typedef int t_Array;
int main(int argc, char* argv)
|
by: tuko |
last post by:
Hello kind people.
Can someone explain please the following code?
/* Create Storage Space For The Texture */
AUX_RGBImageRec *TextureImage; /* Line 1*/
/* Set The Pointer To NULL */
memset(TextureImage,0,sizeof(void *)*1); /* Line 2*/
According to my knowledge in the first line
|
by: junky_fellow |
last post by:
According to Section A6.6 Pointers and Integers (k & R)
" A pointer to one type may be converted to a pointer to another type.
The resulting pointer may cause
addressing exceptions if the subject pointer does not refer to an
object suitably aligned in storage. It is
guaranteed that a pointer to an object may be converted to a pointer to
an object whose type requires less
or equally strict storage alignment and back again without change;...
| |
by: Alexei A. Frounze |
last post by:
Hi all,
I have a question regarding the gcc behavior (gcc version 3.3.4).
On the following test program it emits a warning:
#include <stdio.h>
int aInt2 = {0,1,2,4,9,16};
int aInt3 = {0,1,2,4,9};
|
by: aegis |
last post by:
Given the following:
int a = 10;
int *p;
void *p1;
unsigned char *p2;
p = &a;
|
by: bluejack |
last post by:
Ahoy... before I go off scouring particular platforms for specialized
answers, I thought I would see if there is a portable C answer to this
question:
I want a function pointer that, when called, can be a genuine no-op.
Consider:
typedef int(*polymorphic_func)(int param);
|
by: fieldfallow |
last post by:
Hello all,
Before stating my question, I should mention that I'm fairly new to C.
Now, I attempted a small demo that prints out the values of C's numeric
types, both uninitialised and after assigning them their maximum defined
values. However, the output of printf() for the long double 'ld' and the
pointer of type void 'v_p', after initialisation don't seem to be right.
The compiler used was gcc (mingw) with '-Wall', '-std=c99' and
|
by: Martin Jørgensen |
last post by:
Hi,
"C primer plus" p.382:
Suppose we have this declaration:
int (*pa);
int ar1;
int ar2;
int **p2;
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |