Question:
Create a program that will accept a string value?
j. oslwad
2010-05-08 01:28:25 UTC
Create a program that will accept a string value, then, the program should replace the last letter of the string "x".

Ex.
Input a string: tarlac
Answer is: tarlax
Five answers:
Paul
2010-05-08 02:35:40 UTC
#include

#include



int main(void)

{

....char buff[256];

....int len;



....gets(buff);

....len = strlen(buff);

....if (len > 0)

....{

........buff[len - 1] = 'x';

....}

....puts(buff);

....return 0;

}
PaulC
2010-05-08 01:38:30 UTC
You don't really need to create a formal program. You could just do a search and replace in ms word using pattern matching.



for example: do a search and replace:



find: ^?^w



replace: x



In ms word this ^? means match any character and ^w is white space so the last letter in a word will look like: "test " so "t " will be replaced with "x " to become "testx ". To get fancier you could use a program like UltraEdit32 or many free programs. UE and others can also automatically search inside text files and make the replacement. Pattern matching is pretty easy but it takes effort to get the search and replace to correctly handle all the situations it will encounter.
anonymous
2016-04-14 01:47:40 UTC
Your main program takes "String[] args" as parameter. This is the one which reads the command line arguments when you run it. Please refer to link below on how to read command line arguments. Once you read that you should be able to solve this tutorial easily. Let us what all you can write. If you are not able to complete it 100% post whatever code u have written here. .../
Ravi
2010-05-08 04:37:50 UTC
char name[10];

printf("Enter a string");

scanf("%s",name);

int length=0,i;

for(i=0;name[i]!='\0';i++)

length++;



name[length-1] = 'x';



printf(name);



Write the above code in main function and execute. You will gwt the desired result.
anonymous
2010-05-08 01:39:54 UTC
class Program

{

static void Main(string[] args)

{

string stringIn;



while (true)

{

stringIn = null;

stringIn = Console.ReadLine();



if (stringIn.Length == 0) break;



string result = stringIn.Substring(0, stringIn.Length - 1) + "x";



Console.WriteLine(result);

}

}

}


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...