C program language: -
#include <stdio.h>
-
#include <stdlib.h>
-
#include <string.h>
-
#include <iostream>
-
-
-
int main()
-
{char a[100],b[100],*pa,*pb;
-
pa = &a; pb = &b;
-
scanf("%s",*pa);
-
scanf("%s",*pb);
-
printf("vnesi 2 niza / input 2 strings");
-
printf("\nstring: %s",*pa);
-
printf("string: %s",*pb);
-
system("pause");
-
return 0;
-
}
-
well i dont know how to connect string and a pointer
pa = &a; pb = &b; i presume that problem is only here but i cant corect it.
3 1232
C program language:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
int main()
{char a[100],b[100],*pa,*pb;
pa = &a; pb = &b;
scanf("%s",*pa);
scanf("%s",*pb);
printf("vnesi 2 niza / input 2 strings");
printf("\nstring: %s",*pa);
printf("string: %s",*pb);
system("pause");
return 0;
}
well i dont know how to connect string and a pointer
pa = &a; pb = &b; i presume that problem is only here but i cant corect it.
Ok, A and B are already pointers so you don't have to get the addresses. If you want a pointer to a char array, you need a pointer to a pointer.
Banfa 9,065
Expert Mod 8TB
Ok, A and B are already pointers so you don't have to get the addresses. If you want a pointer to a char array, you need a pointer to a pointer.
No on the whole this is rather wrong!
Banfa 9,065
Expert Mod 8TB
This is not wrong
but this would be more conventional
Generally speaking for an array a as you have defined it the a == &a, the only difference is the type of the expression.
However you 1st actual problem is in your scanf lines -
scanf("%s",*pa);
-
scanf("%s",*pb);
-
%s tells scanf to expect a pointer to char but you pass a char, *pa these should be -
scanf("%s",pa);
-
scanf("%s",pb);
-
And then you make the same mistake in your printf calls -
printf("\nstring: %s",*pa);
-
printf("string: %s",*pb);
-
should be -
printf("\nstring: %s",pa);
-
printf("string: %s",pb);
-
However on the whole in this program pa and pb are completely superfluous, you could get rid of them and replace them with a and b.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Michael B. Allen |
last post by:
Coming from C and Java on *nix I'm a little out of my element messing around
with CList and MSVC++ but I think my issues are largely syntactic.
I have an ADT that I use called a 'varray' that can...
|
by: agent349 |
last post by:
First off, I know arrays can't be compared directly (ie: if (arrary1
== array2)). However, I've been trying to compare two arrays using
pointers with no success. Basically, I want to take three...
|
by: Ian Todd |
last post by:
Hi,
I am trying to read in a list of data from a file. Each line has a string in
its first column. This is what i want to read. I could start by saying
char to read in 1000 lines to the array( i...
|
by: Rainmaker |
last post by:
Hi,
Can anyone tell me an efficient algorithm to sort an array of strings?
Keep in mind that this array is HUGE and so the algorithm should me
efficient enough to deal with it.
Thanks
|
by: Steven |
last post by:
Hello,
I have a question about strcmp(). I have four words, who need to be
compared if it were two strings. I tried adding the comparison values
like '(strcmp(w1, w2) + strcmp(w3, w4))', where...
|
by: Aris |
last post by:
A few days ago I asked from you how to join a string like "file"
A number that change values from 1 to 5 and another string like ".txt"
to have a result like "file1.txt","file2.txt" and so on
...
|
by: Dadio |
last post by:
Hi!
I have to take some strings from a file and put them in a record...
The various strings in the file are written on this way:
string1|string2|string3|string4|string5|
This is the program...
|
by: CoreyWhite |
last post by:
/* WORKING WITH STRINGS IN C++ IS THE BEST WAY TO LEARN THE LANGUAGE
AND TRANSITION FROM C. C++ HAS MANY NEW FEATURES THAT WORK TOGETHER
AND WHEN YOU SEE THEM DOING THE IMPOSSIBLE AND MAKING...
|
by: InDepth |
last post by:
Now that .NET is at it's fourth release (3.5 is coming soon), my very humble
question to the gurus is:
"What have we won with the decision to have string objects immutable? Or did
we won?"
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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,...
|
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...
|
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,...
|
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...
| |