C :: Scanning 2 Strings In Same Scanf Call

Nov 20, 2013

Somehow only str2 is successfully scanned and str1 is not printed

Code:

printf("
Please enter two times in this way xx.xx xx.xx now ");
scanf("%s%s", str1, str2);
printf("
%s - %s:
", str1, str2)); result : - str2:

View 3 Replies


ADVERTISEMENT

C++ ::  assignment Is Recursive Call And Placing Strings In Linked List Notes

Oct 24, 2013

You need to write a permute class that will take first and second strings to rearrange letters in first, followed by second. For example, if the first is “CAT” string and second is “MAN” string, then the program would print the strings TACMAN, ATCMAN, CTAMAN, TCAMAN, ACTMAN, and CATMAN. The first and second strings can be any length of string or a null.

The permute class uses a Note class as link list note to link all letters arrangement. The permute class has Note pointers, firstNote and lastNote, to point to the beginning and ending Notes of the link list as private data members. There are three other private data members (total, firstString and secondString) to store the total possible number of arrangements and strings pass into the class.

Write a driver to test the permute class to pass in any two strings of any sizes.

Other than mention in the following, you can add more classes, functions, and private data members to this program.

Note class

The Note class needs to have two private data members and a constructor. The two private data members are data and p pointer. The data’s data type is string and p pointer is Note. The Note class constructor has two parameters, one is string and the other is Note pointer.

Permute class

The Permute class has five private data members (*firstNote, *lastNote, total, firstString and secondString). The firstNote and lastNote pointers are point to Note. The total has integer data type. The firstString and secondString have string data type.

There should have at least three public member functions, Permute, permutation and print. The Permute function is the constructor which takes strings to initialize the private data members. The permutation function does the recursive call to arrange the strings and setup the link list. The print function will print out the private data member information.

Driver file

The driver file should declare a Permute eight elements pointer array. Instantiate eight Permute object with the following eight set of data and assign the object to the pointer array. Use a repetition to call the object’s print function to print out the private data member information. If the total of the permute private data member is less than 100 then print out the permutated letters four in a row, otherwise print out 9 in a row.

first = "", second="",
first = "", second ="CATMAN",
first = "C", second ="ATMAN",
first = "CA", second ="TMAN",
first = "CAT", second ="MAN",
first = "CATM", second ="AN",
first = "CATMA", second ="N",
first 1 = "CATMAN", second ="";

View 19 Replies View Related

Visual C++ :: Assignment Is Recursive Call And Placing Strings In Link List Notes?

Oct 30, 2013

You need to write a permute class that will take first and second strings to rearrange letters in first, followed by second. For example, if the first is “CAT” string and second is “MAN” string, then the program would print the strings TACMAN, ATCMAN, CTAMAN, TCAMAN, ACTMAN, and CATMAN. The first and second strings can be any length of string or a null.

The permute class uses a Note class as link list note to link all letters arrangement. The permute class has Note pointers, firstNote and lastNote, to point to the beginning and ending Notes of the link list as private data members. There are three other private data members (total, firstString and secondString) to store the total possible number of arrangements and strings pass into the class.

Write a driver to test the permute class to pass in any two strings of any sizes.

Other than mention in the following, you can add more classes, functions, and private data members to this program.

Note class:The Note class needs to have two private data members and a constructor. The two private data members are data and p pointer. The data’s data type is string and p pointer is Note. The Note class constructor has two parameters, one is string and the other is Note pointer.

Permute class:The Permute class has five private data members (*firstNote, *lastNote, total, firstString and secondString). The firstNote and lastNote pointers are point to Note. The total has integer data type. The firstString and secondString have string data type.

There should have at least three public member functions, Permute, permutation and print. The Permute function is the constructor which takes strings to initialize the private data members. The permutation function does the recursive call to arrange the strings and setup the link list. The print function will print out the private data member information.

Driver file:The driver file should declare a Permute eight elements pointer array. Instantiate eight Permute object with the following eight set of data and assign the object to the pointer array. Use a repetition to call the object’s print function to print out the private data member information. If the total of the permute private data member is less than 100 then print out the permutated letters four in a row, otherwise print out 9 in a row.

first = "", second="",

first = "", second ="CATMAN",

first = "C", second ="ATMAN",

first = "CA", second ="TMAN",

first = "CAT", second ="MAN",

first = "CATM", second ="AN",

first = "CATMA", second ="N",

first 1 = "CATMAN", second ="";

View 3 Replies View Related

C# :: How To Multithread Port Scanning App

Jan 24, 2012

I'm creating a small port scanning app which use a port range defined by user.My problem with the code is that I find it not efficient enough meaning that it ping very slow, especially when ports are not responding meaning that I must wait for the timeout before continuing to next port.

I want to make this small app threaded. The problem here is that I'm kind of blank of how to implement threading in my program. This is my code which is a method which does the actual checking, the other part of the code is a simple button with for loop for advancing my port number.

Code:

private void ScanPort(IPAddress address, int port) {
using (TcpClient client = new TcpClient() {
IAsyncResult result = client.BeginConnect(address, port, null, null);

if (result.AsyncWaitHandle.WaitOne((int)nudTimeout.Value, false)) txtDisplay.AppendText("Port: " + port + " is open." + Environment.NewLine);
else txtDisplay.AppendText("Port: " + port + " is closed." + Environment.NewLine);
} }

I have read some basic threading tutorial but I just don't know how to implement this piece of code so I can check ports much faster.

View 3 Replies View Related

C :: Scanning CSV File And Assigning Variable To It

Dec 26, 2013

How to scan a CSV file and assigned variable to each of the integer scanned in a csv file

an example of the csv file:
0001,40,,10

How do I scan the CSV file and assign 0001 to variable student id, the 40 to variable module 01,the 1 without input entered to module02 and 10 to module03

View 6 Replies View Related

C :: Scanning Characters Into A Multidimensional Array

Mar 19, 2014

I have initialized a multidimensional array eg char fruit[5][10]...Then I would need to read in 3 words with spaces in between from user and store in fruit[5][10] e.g "pear apple orange"

The thing is that after typing orange, when I press Enter it still prompts me to enter more characters. How can I end the scanning of characters after orange ?

View 4 Replies View Related

C :: Scanning Equations / Functions Into Program

Nov 15, 2014

I have to make a numerical integration program, how I can write my code so that the user is able to write their own function that they want to integrate?

E.g. they would see the message: 'please enter your function' and would be able to write whatever they wanted e.g. 'x +5' then this would then be integrated by the program.

I have already written a program that can integrate a known function but would prefer that the user could choose their own.

View 2 Replies View Related

C/C++ :: Scanning CSV File Into Array Of Structs

Mar 18, 2015

I need to scan a .csv file that contains the following info:

programming,03,60,141,01,W,2015
programming,03,60,141,30,W,2015
Algebra,03,62,102,02,S,2013
Religion,08,98,938,20,F,2014

So i made a struct:

typedef struct CourseInfo {
int courseID;
char courseName[50];
char courseCode[13];
char term[7];
} courseinfo;

Where course code is the 4 numbers after the name together and the term is the letter and year in the last two pieces of info. I got this to work:

int main() {
FILE *p;
p = fopen("input.csv", "r+");
if(p == NULL) {
puts("The file could not be opened");

[Code] ......

But lets say i dont know how many lines i have in my file and i want to count them and then use that size for my array so i tried this by:

int main() {
FILE *p;
int lines = 1;
char ch;
p = fopen("input.csv", "r+");
if(p == NULL) {

[Code] .....

But the second program is not working for unknown reasons. I do not get any errors but its not scanning the info because when i print the info later on it prints out random symbols.

View 11 Replies View Related

C/C++ :: Error In Scanning Database Names

Feb 13, 2014

I'm working on a program to store student's names, ID, and GPA, but for some reason the first and last name of the student are copied into every name of the database array once I scan them, regardless of whether or not add_student even runs.

typedef struct{
char *f_name;
char *l_name;
int stud_id;
double gpa;
} student_t;
int add_student(student_t db[], char fname[], char lname[], int iden, double grade, int db_size){
int i, error;

[Code] ....

For example, if I type "a Adam Johnson 1234 4.00" it'll add the first student with name Adam Johnson. However, if I try to add another student named "Kyle Walker", it overwrites "Adam Johnson" with "Kyle Walker" as soon as the names are scanned.

View 3 Replies View Related

C :: Scanning A File With Words And Int / Float Numbers

Dec 1, 2013

scanning a file with both words and INT's/Float numbers. This is the file data here.

15 25 200
3 10
17.99 22.99 109.99
100 2 4
5.99 99.99 20.00 49.99
10 10 10 10 10 10 10 10 10 10
3.99 5.99 7.99 8.00 5.00 5.00 5.00 6.00 7.00 9.99

[Code]...

What I'm focused on is reading in the first three numbers which I already have with fscanf and then reading in BUY TICKET with the digit afterwards. My problem is that I don't know how to reach that part of the file without scanning in something I don't want to. Also, how would I scan the number after scanning BUY TICKET? Would it be something like using %s and %d right afterwards?

View 4 Replies View Related

C :: Scanning 2 Dimensional Array For Duplicate Values

Mar 26, 2013

I am trying to scan a 2 dimensional array to see if there are any duplicates within a row or column; i.e. the concept of a sudoku game.how to scan a row or column one at a time.

View 1 Replies View Related

C++ :: Scanning A Header File To Save Image Data

Jun 11, 2013

I'm trying to read from a header file to take the image dimensions and other variables but I don't understand how to iterate through the "key" so it saves each line.

This is what the header file will always look like:

!INTERFILE :=
!imaging modality := nucmed
!version of keys := 3.3
;
!GENERAL DATA :=

[Code].....

Ideally it would just skip the keys that aren't wanted and keep moving through the lines. Should there be a for loop for the key (and if so, how does that work with pointers?) or should this method just be scratched...

View 6 Replies View Related

C :: Scanning Words Into Binary Search Tree - No Stack Error Diving Seg Fault

Apr 2, 2013

This is the first time I have encountered a "no stack." error giving me a seg fault. Anyhow, I am scanning words into a binary search tree and it is giving me a seg fault.

Here is the file (words.txt):
4
bravo
alpha
gamma
delta

Code:
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

typedef struct node_t{
char *word;
struct node_t *left;
struct node_t *right;

[Code] .....

View 5 Replies View Related

C :: How To Put Value From Scanf Into Array

May 2, 2013

Code:

#include<stdio.h>
#include<windows.h>
int nr, i, array_new[10],n=0;
main(){
printf ("Insert number: ");
scanf ("%d", &nr);

[Code]...

I need put value from scanf into array. How make this: array_new[nr]?

View 8 Replies View Related

C :: Using Scanf In If / Else Statement

Aug 7, 2013

When I do this:

Code:

#include <stdio.h>
#include <stdlib.h>
int main () {
int guess ;
int number = 5 ;

[Code] .....

But when I do this:

Code:
#include <stdio.h>
#include <stdlib.h>
int main () {
int guess ;
int number = 5 ;

[Code] ....

Why does the compiler say that there is an else without a previous if ??? ... Does this mean that I cannot use "scanf" in an if/else statement?

View 2 Replies View Related

C :: How To Scanf To Integer Or Char

Feb 6, 2014

I have to make a program for school to evalute poker hand.I am not asking about the logic of the program,I am asking because I have to take the input from the console,five lines which can be the cards 2,3,4..10 and the problem is with J,Q,K,A ,because I dont know how to tell scanf to expect integer or char ? If I type J,Q,K,A the program crash ,

View 1 Replies View Related

C :: Get Rid Of Space / Use Scanf Or Getchar

Sep 24, 2014

I want the user to be able to enter a command then a character, like for example: push r....I want the command to be stored in the array command, and the character to be stored in the variable c.

Now I wonder what the best way to get rid of the space is, using scanf or getchar (see below for code, only thing that I changed between the 2 versions is the statement before the comment "get rid of space")? Or maybe it doesnt matter?

Code:

include <stdio.h>
#define MAX 200
void push(char c); // Puts a new element last in queue
char pop(void); // Gets the first element in queue
static char s[MAX];
}

[code]....

View 6 Replies View Related

C :: Getting Char As Input By Scanf

Mar 31, 2014

In GCC v4.6, I am encountering a strange problem. If I try to get a character input and a int input like this:

Code:

int main()
{
int a;
char b;
scanf("%d",&a);
scanf("%c",&b);
}

the compiled program asks for input only one time. On the other hand, if I do the char scanf earlier like this:

Code:

int main()
{
int a;
char b;
scanf("%c",&b);
scanf("%d",&a);
}

it asks for input twice.

View 6 Replies View Related

C :: How To Write Scanf With Right Parameters

Jun 30, 2013

How can i upgrade my program I want to input a octal and binary number and convert them in base 2, 8, 10, 16..

how can I write the scanf with the right parameter in it??

Code:
scanf ("%x",&i); Code: #include<stdio.h>
#include<conio.h>
#include<stdlib.h>
int main() {
int i;
char buffer [33];

[Code] .....

View 5 Replies View Related

C :: Scanf / Fgets Without Echo

Aug 31, 2014

I am trying to write a terminal-like chat application in Linux. I would like to use a FIFO queue to print out the messages in terminal. The queue would be populated from 2 sources- stdin and messages sent from the other user over TCP. I have meet an obstacle that I cannot handle...

Lets say I would like to take user input using fgets and put it into a buffer. Then queue it if the buffer is not empty or print if it is. The problem is that when I use fgets or scanf, my input is instantly printed to the terminal..If i do:

Code:

fgets(message, 100, stdin); printf

("%s", message The string under message is printed twice :|. Is there a way to prevent this?

View 5 Replies View Related

C :: Scanf With Stopping Condition

Mar 22, 2013

I wanted to input some numbers with scanf function, i can enter some numbers and if I input -1 to the scanf, the input must end. And the scanf function has limited input, the max that I can input is 40 numbers.example if enter 1 2 4 6 5 4 -1 the scanf function will ended and the result will be appear.I wanted to know how the scanf function is like that would be best for this problem, Code: scanf("%d", &n); the result if I input those number will be like

|
||
||||
||||||
|||||
||||

View 3 Replies View Related

C :: How To Scanf Inputs Into Array

Nov 23, 2014

I don't know how many numbers will be the input only that its going to be up to 10000. EOF should be active. I tried it like this:

Code:

int i = 0;
int del[10000]
while (scanf("%d",del[i])!=EOF)
{
i++;
}

But it seems the value of i doesn't increment, could you provide some tips on how to scanf the inputs into an array if I don't know how many numbers will I have?

View 7 Replies View Related

C :: Scanf Is Skipped In Run Window

Jul 11, 2014

when i run it , it skips scanf and not allowing user to enter input.tried adding getchar(), fflush but nothing worked for me.
//file name : sort_array_of_structure.c

Code:

/*Write a program to accept records of the different states using array of structures. The structure should contain char state, population, literacy rate, and income. Display the state whose literacy rate is highest and whose income is highest.*/

#include <stdio.h>
#define M 50
struct state
{
char name[50];
long int population;
float literacyRate;
float income;
}

[code]....

View 3 Replies View Related

C/C++ :: Checking For A Space In Scanf

Jan 23, 2014

I have created a prompt which prompts the user for an integer and I have set up a loop to check for if it is an integer or not. My "bug" is that a user can enter an "integer" and "space" and "enter" and it does not give any error and assumes that "All is FINE!". I have gotten the value from the ascii table of 'SPACE' and put it as a check in my parameter of while, but it does not work.

Here is my code:

int x, y, boolean, i;
char buff[256];
printf("Enter the first integer value: ");
scanf("%s", buff);
i = 0;
boolean = 0; //initializing our boolean var that will eventually decide if we have an error or not

[code]....

View 4 Replies View Related

C++ :: How To Flush Scanf Buffer In C

Oct 10, 2014

I am writing a program and am asking the user to enter a number between 1-12.

If they do not, they will be promoted over and over again to enter a number between 1-12.

However, if the user enters a letter or anything else scanf seems to stop working and then my loop goes out of control.

View 2 Replies View Related

C++ :: Input Using Printf / Scanf

Oct 28, 2014

How to store the value in this case.. The topic is called "limited summation".. The following is the guideline for this problem:

Write a program in a folder called "sum" with a source file of main.cpp that does the following:

•prompt a user to enter a maximum number of entries, make the prompt "max # entries"

•prompt a user to enter a threshold sum, make the prompt "threshold"

•using error checking logic, let a user enter base-10 signed numbers until at least one of the following conditions is true:

or the maximum number of entries is reached
or the sum of entered numbers has reached (>=) the threshold

•print the sum of all the entries, just the number and a linefeed at the end of the line

Error checking means entries that are not numbers are detected and ignored. You are to use printf and scanf in this assignment (no cin or cout).

View 3 Replies View Related







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