C
c
Hi everybody.
I'm working on converting a program wriiten on perl to C, and facing a
problem with concatenate strings.
Now here is a small program that descripe the problem, if you help me
to solve in this small code, I can solve it on my own program...you
don't want to have head-ache
So, the problem excatly is, I built an array..just like this one.
char *my_array [10];
my_array[0] = "Sally\n";
my_array[1] = "Ndiya\n";
my_array[2] = "Samantha\n";
my_array[3] = "Sara\n";
my_array[4] = "Cadillac\n";
my_array[5] = "GM For Ever\n";
my_array[6] = "SlacWare\n";
my_array[7] = "Google\n";
my_array[8] = "Google more and more\n";
my_array[9] = "You\n";
my_array[10] = "Computers\n";
my program will recieve an argument -char *argv[]- from the user.
int main(int argc,char *argv[])
I want to concatenate the given argument to at the first of each line
of my array.
so, if we imagine the array after the concatenating, it would look like
this (suppose the given argument is "ILove").
my_array[0] = "ILoveSally\n";
my_array[1] = "ILoveNdiya\n";
my_array[2] = "ILovesamantha\n";
my_array[3] = "ILoveSara\n";
my_array[4] = "ILoveCadillac\n";
my_array[5] = "ILoveGM For Ever\n";
my_array[6] = "ILoveSlacWare\n";
my_array[7] = "ILoveGoogle\n";
my_array[8] = "ILoveGoogle again\n";
my_array[9] = "ILoveSAMI\n";
my_array[10] = "ILoveComputers\n";*/
I tried strcat() -strings.h- but the result wasn't what I'm looking
for.
read the code..and the comments will help to understand the
problem..here is the whole code of my problem example.
#include <stdio.h>
int main(int argc,char *argv[])
{int i=-1;
char *my_array [10];
my_array[0] = "Sally\n";
my_array[1] = "Ndiya\n";
my_array[2] = "Samantha\n";
my_array[3] = "Sara\n";
my_array[4] = "Cadillac\n";
my_array[5] = "GM For Ever\n";
my_array[6] = "SlacWare\n";
my_array[7] = "Google\n";
my_array[8] = "Google more and more\n";
my_array[9] = "You\n";
my_array[10] = "Computers\n";
while(i++ < 10)
{
printf(argv[1]); //Don't do it like this..read my comments please.
printf(my_array);
}
// I need your help to fix below loop, I want to cancatenate the given
data -*argv[]- to each line of my array.
// For Example, if the user enetered
// root@localhost# test ILove
// the result would be:
// ILoveSally
// ILoveNdiya
// ..etc
//
//But don't do it by printting the given data followed by my_array
lines(I mean by printting it twoice), because I need the given data to
be concatenated at the first of each line of my array.
//So, my_array would look like this
// my_array[0] = "ILoveSally\n";
// my_array[1] = "ILoveNdiya\n";
// my_array[2] = "ILovesamantha\n";
// my_array[3] = "ILoveSara\n";
// my_array[4] = "ILoveCadillac\n";
// my_array[5] = "ILoveGM For Ever\n";
// my_array[6] = "ILoveSlacWare\n";
// my_array[7] = "ILoveGoogle\n";
// my_array[8] = "ILoveGoogle again\n";
// my_array[9] = "ILoveSAMI\n";
// my_array[10] = "ILoveComputers\n";*/
while (i++ < 10)
{
// type your code here..Thanks
}
return 0;
}
thank you for your time.
I'm working on converting a program wriiten on perl to C, and facing a
problem with concatenate strings.
Now here is a small program that descripe the problem, if you help me
to solve in this small code, I can solve it on my own program...you
don't want to have head-ache
So, the problem excatly is, I built an array..just like this one.
char *my_array [10];
my_array[0] = "Sally\n";
my_array[1] = "Ndiya\n";
my_array[2] = "Samantha\n";
my_array[3] = "Sara\n";
my_array[4] = "Cadillac\n";
my_array[5] = "GM For Ever\n";
my_array[6] = "SlacWare\n";
my_array[7] = "Google\n";
my_array[8] = "Google more and more\n";
my_array[9] = "You\n";
my_array[10] = "Computers\n";
my program will recieve an argument -char *argv[]- from the user.
int main(int argc,char *argv[])
I want to concatenate the given argument to at the first of each line
of my array.
so, if we imagine the array after the concatenating, it would look like
this (suppose the given argument is "ILove").
my_array[0] = "ILoveSally\n";
my_array[1] = "ILoveNdiya\n";
my_array[2] = "ILovesamantha\n";
my_array[3] = "ILoveSara\n";
my_array[4] = "ILoveCadillac\n";
my_array[5] = "ILoveGM For Ever\n";
my_array[6] = "ILoveSlacWare\n";
my_array[7] = "ILoveGoogle\n";
my_array[8] = "ILoveGoogle again\n";
my_array[9] = "ILoveSAMI\n";
my_array[10] = "ILoveComputers\n";*/
I tried strcat() -strings.h- but the result wasn't what I'm looking
for.
read the code..and the comments will help to understand the
problem..here is the whole code of my problem example.
#include <stdio.h>
int main(int argc,char *argv[])
{int i=-1;
char *my_array [10];
my_array[0] = "Sally\n";
my_array[1] = "Ndiya\n";
my_array[2] = "Samantha\n";
my_array[3] = "Sara\n";
my_array[4] = "Cadillac\n";
my_array[5] = "GM For Ever\n";
my_array[6] = "SlacWare\n";
my_array[7] = "Google\n";
my_array[8] = "Google more and more\n";
my_array[9] = "You\n";
my_array[10] = "Computers\n";
while(i++ < 10)
{
printf(argv[1]); //Don't do it like this..read my comments please.
printf(my_array);
}
// I need your help to fix below loop, I want to cancatenate the given
data -*argv[]- to each line of my array.
// For Example, if the user enetered
// root@localhost# test ILove
// the result would be:
// ILoveSally
// ILoveNdiya
// ..etc
//
//But don't do it by printting the given data followed by my_array
lines(I mean by printting it twoice), because I need the given data to
be concatenated at the first of each line of my array.
//So, my_array would look like this
// my_array[0] = "ILoveSally\n";
// my_array[1] = "ILoveNdiya\n";
// my_array[2] = "ILovesamantha\n";
// my_array[3] = "ILoveSara\n";
// my_array[4] = "ILoveCadillac\n";
// my_array[5] = "ILoveGM For Ever\n";
// my_array[6] = "ILoveSlacWare\n";
// my_array[7] = "ILoveGoogle\n";
// my_array[8] = "ILoveGoogle again\n";
// my_array[9] = "ILoveSAMI\n";
// my_array[10] = "ILoveComputers\n";*/
while (i++ < 10)
{
// type your code here..Thanks
}
return 0;
}
thank you for your time.