C :: How To Print The String In Main

May 23, 2013

if you have something like this how can you print the string in main??

Code:

/#include <stdio.h>
#include <stdlib.h>
void myf(char *p)
{
p="balls";
}
int main()
{

[Code]...

View 2 Replies


ADVERTISEMENT

C :: How To Print Out Recursive Function In Main

Feb 9, 2013

I am just practicing some recursion and I am having trouble with printing out a recursive function in main. Here is what I have:

Code:

// This function adds the squares 4, 5 = 4*4 + 5*5 recursiveley
int recursive_sumSquares(int m, int n) {
if (m < n) {
return m*m + recursive_SumSquares(m+1, n);
}
else {
return m*m;

[Code]...

I am getting an error that says undefined reference to 'recursive_SumSquares'

View 2 Replies View Related

C :: Passing A String To A Function From Main?

Mar 30, 2014

i would like to know if i need to dynamically allocate a string in main before passing it to a function that i have created.

in that function i just read the string and do not change any chat in it.

View 2 Replies View Related

C :: Return A String To Then Call It On Main Function?

May 26, 2013

I'm trying to return a string to then call it on main function.

Code:
const char* coiso(int chave){
char str [50];
sprintf(str,"%d",chave);
char txt[50] = ".txt";
strcat(str,txt);
return str;
}
int main () {
const char* info = coiso(8);
printf("%s",info);
}

If I do a printf("%s",str) in coiso function it works but the following code doesn't work.

View 10 Replies View Related

C :: String Declaration As Global / Main Local Variable

Nov 14, 2013

When a declare a string e.g.

Code:
char str[30]; as a global variable, the srting is initialized to NULL.

But if I declare char str1[30] INSIDE main(), then the string has garbage inside.... Why this happens??

E.g. the following code snippet...

Code:
#include <stdio.h>
char str[50];
int main(){
char str1[50];

[Code] ....

View 4 Replies View Related

C :: Declared A String Constant And Trying To Print Length Of String

Oct 9, 2014

In this code, i declared a string constant and trying to print the length of string. I know that if i write char a1[7] or char a1[] than it runs and give aggregate output, but in this case it is giving double length of string.

Code:

#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
}

[code]....

View 5 Replies View Related

C :: Print First Word Of The String

Apr 12, 2013

1. Create a variable named index and nitialize it to zero(0)
2. Prompt for and input a string value from thekeyboard. Store the string inthe string variable newstring[80].
3. While (newstring[index] does not equal ‘’).

i. Display the character at newstring[index] followed by a NL
ii. Increment index ====================================== ...

And this is what i have done so far and i dont know where I am wrong ...

Code:
#include<stdio.h>
int main()
{
int index = 0; //initialize index to zero since first elementin an array is numbered zero
char newstring[80];

[Code] ....

View 3 Replies View Related

C :: Print Words Of A String

Dec 4, 2013

I want to print the words of a sentence, given as a string..But I have a problem with the end of the sentence, and cannot find the bug....

Code:

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
char str[80]="This is a sentence";
int main(){
}

[code].....

View 7 Replies View Related

C :: Program To Print The Length Of A String

Oct 20, 2013

Well what the title says, but I can't get it done. This is what I got

Code:
#include <stdio.h>#include <string.h>
int main(void)
{
char word;
int count;
printf("Enter a word.

[Code] ....

View 4 Replies View Related

C :: Making A String Print In Reverse

Oct 15, 2013

Here's what I have to do: Using strcpy() pass it two strings of characters (such as a name like John Johnson) and copy the second string into the first, in reverse order, and print both. Write a main to exercise your function and to illustrate that the function is working properly.

View 4 Replies View Related

C :: Print String With Escape Characters

Mar 7, 2013

is there any function to print a string with all the escape characters in it?

For example, instead of printing:
This is a string.

It would print:
This is a string.

Or in Windows:
This is a string.

I know that you can debug the code to find the variable contents, but is there any way to accomplish this with some standard library function?

View 6 Replies View Related

C++ :: Longest String Does'n Print On Same Line

Aug 4, 2014

I try to learn string class, resolving some problem, but i have some dificulties.The is ok, but when i print the longest string it does'n print on the same line.I enter the number of string, after that i enter the first string until i introduced from keyboard "#" character. I enter the second string and so on.Look at these example :

For i = 3;

Text[0] : I learn class String#
Text[1] : I dont learn class String#
Text[2] : String#

It print me like that : Text[1] :

I dont learn class String More than that look at the next example :

For i = 3;

Text[0] : I learn class String#abcdef
Text[1] : I dont learn class String#
Text[2] : String#

You see that in the first sentence i have continue to introduce some characters after # character and look what is happened :

Text[1] : abcdef
I dont learn class String

#include<iostream>
#include<string>
using namespace std;
int main() {
string text[100], cuvant;
int i, j, m, lung = 0;
cout << "

[code]....

View 3 Replies View Related

C/C++ :: Make Program To Print Out String

Nov 24, 2014

I'm trying to make a program in C where the user enters a string and it prints a word for example (name) in lowercase then the same word again but in capitals and lowercase like this (NnAaMmEe).

my code is below;

#include<stdio.h>
#include<ctype.h>
int main()

[Code].....

View 1 Replies View Related

C++ :: Store And Print String On Screen

Sep 20, 2013

Given this sentence as an input: "Hello my name and "John" (with its spaces and capital letters), print it on the screen .. NB the phrase must be entered from the keyboard all at once ... you can do this in C / C + +?

View 3 Replies View Related

C++ :: How To Print String In Uppercase Format

Feb 17, 2012

I have a problem. I need to print the string called "last" in uppercase format. can you check why my program prints nothing.

Here is the important section of the code.

if (infile.is_open()) // if file was able to open {
string line;
while (getline(infile, line)) {
string::size_type pos1 = line.find(' '); //pos1 is the position of the first space

[Code] ....

View 1 Replies View Related

C :: Cycling Through Memory To Print String With And Without Function

Feb 10, 2014

Anyways, I have a problem where I'm trying to cycle through memory via pointers to print a string. Here is my code:

Code:

#include <stdio.h>
int main(void){
char word[]="hello there";

[Code]....

This seems to effectively portray what I want

How do I print a string using the same method for(;*pointer!='/0';pointer++) without a function?

View 2 Replies View Related

C++ :: Mapping Strings To Integers - How To Print String Zero

Dec 12, 2013

I'm very very new to maps and am really just trying to hash them out by myself.

If you're mapping strings to integers:

map <string, int> myMap;
myMap[ "zero" ] = 0;
myMap[ "one" ] = 1;

How do I print the string "zero", for instance, from myMap?

cout << myMap.at(0) << endl;

doesn't work. Nor does:

cout << static_cast<string>( myMap.at(0) ) << endl;

I need access to the string using the int and the int using the string. Or just direct access to one or the other. . . It's just confusing that they're technically mapped to one another but I can't really access either of them.

View 4 Replies View Related

C :: How To Print Out Output String For A Program In Reverse / Backwards

Feb 20, 2013

How to make it so an output for a program would print out the string in reverse/backwards? I was just curious on how to do this.

View 6 Replies View Related

C++ :: Turbo Code To Print String Through Installed Printer

Nov 10, 2013

C++ Code To Print String through Installed Printer. How to user Printer File Name?

View 9 Replies View Related

C++ :: Print Pattern Function That Handles Parameter As String

Sep 26, 2013

How to write a printPattern() function?

The function takes in a parameter i.e. a char pointer. It handles the parameter as a Cstyle string i.e. a NULL terminated char array. It does not make use of the stringclass or its associated functions. In other words, the function examines every char element in the array until it encounters the terminating NULL character.

Starting from this int main :

int main() {
char string1[] = "Application of C++";
printPattern(string1);
}

[Code].....

View 1 Replies View Related

C/C++ :: Program To Scan Number And String Then Print Them To A File

Mar 19, 2015

I wrote this program to scan a number and a string until EOF then print them to a file named "data.list". the problem is that the program duplicates last line of input in the output file. so for example if the input is :

1 test
2 dream
3 code

then output (in data.list file) would be:

1 test
2 dream
3 code
3 code

I also changed the program code so that it reads from data.list file. even here it duplicates last line!

so when program reads the info above saved in data.list it would be:

1 test
2 dream
3 code
3 code
3 code

here's the code for writing:

#include <stdio.h>
int main( void )
{
int num;
char str[80];
FILE *fPTR;
fPTR = fopen( "data.list", "w" ); // opens a file named "data.list", create if doesn't exist
while(!feof(stdin)) // loop until End-Of-File is pressed. Ctrl-Z in Windows, Ctrl-D in Unix, Linux, Mac OS X

[Code]...

and the one for reading from file:

#include <stdio.h>
#include <conio.h>
int main( void )
{
int num;
char str[80];
FILE *fPTR;

[Code]...

How do I fix this behavior??

View 3 Replies View Related

C/C++ :: Print Dynamic String To Console Tokenized Using Spaces As Delimiters

Feb 26, 2014

I am having some trouble tokenizing some strings in C. I am trying to take in a string dynamically and spit print it to the console tokenized using the spaces as delimiters. I have tried using frets() and scant() as well as playing around with pointer values to no avail.

#include <stdio.h>
#include <unistd.h>
#include<string.h>
#include <stdlib.h>
#define MAX_LINE 80
//function prototypes
void printArgs(int argc, char* args[]);

[Code] .....

View 7 Replies View Related

C :: How To Print Characters But No String Just Array Of Characters

Mar 20, 2014

so my question is i want to print characters,no string just an array of characters,i do this but it s not working,maybe i have to put the '' at the end?

Code:

int main() {
int i;
char ch[5];
for(i = 0; i < 5; i++) {
scanf("%c",&ch[i]);

[Code]...

View 6 Replies View Related

C :: Won't Print Numbers Sorted When Use Print Function

Nov 17, 2013

I am making a program where the user enters numbers into an array and then a number,x. The array is sorted, then x is inserted into the appropriate place. I wrote my selection sort

Code:

void Sort(int ary[], int size)
{
int temp;
int smallest;
int current;
int move;
}

[code]....

put it wont print the numbers sorted when I use my print function, just the unsorted numbers.

View 1 Replies View Related

C/C++ :: Using Print Statement To Print Certain Number Of Spaces

Sep 1, 2014

is there a to use printf to print certain number of blank spaces, where the number is derived from the output of a function?

for(m=low; m<=high;m++)
{
printf("t=%2d %'f(m)-1's %3c", m, ' ',*);
}

This is suppose to output

t=-3 *
t=-2 *
t=-1
.
.
.

View 2 Replies View Related

C :: Difference Between Two Int Main Functions

Feb 6, 2014

I just wanted to know what's the difference between these two types of main functions:

Code: int main (int argc, char** argv){ ... }

Code: int main (int argc, char* argv[]){ ... }

View 4 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved