C# :: While Statement Not Recognizing Non-null String

Oct 10, 2014

The List[] array contains some empty entries but most are filled, yet every time I run this routine the variable Index makes it to the end of the array. I've tried many different routes and can't seem to figure out this simple issue.

string Result = string.Empty;
while ((Index < (List.Length - 1)) || !string.IsNullOrEmpty(Result))
{
Result = List[Index];
Index++;
}
return Result;

View 9 Replies


ADVERTISEMENT

C++ :: Intellisensor Not Recognizing String Data Type

Apr 26, 2014

So Im working on my semester prject for my programming class. It is to make a roulette game. And Im working on getting my table set up but the intellisensor in my Visual Studio seems to not be working and recognizing the string variable type. Its not changing to blue when I enter it.

This program is a roulette simulation, designed to be used for online gambling.

#include <iostream>
#include <iomanip>
#include <Windows.h>
#include <string>
#include <ctime>
using namespace std;
//Function Prototypes
void welcome();
double getBalance();

[Code] .....

When I run the program it gives me an error as well sometimes. This one: Unhandled exception at 0x0f681f68 (msvcp100d.dll) in Roulette Final Project.exe: 0xC0000005: Access violation reading location 0x8bb59d35.

Which opens another tab named "iosfwd" and points to this bit of code:

static int_type __CLRCALL_OR_CDECL to_int_type(const _Elem& _Ch)
{// convert character to metacharacter
return ((unsigned char)_Ch);
}

View 5 Replies View Related

C++ :: Null Statement - Prevent Optimization

Dec 7, 2014

Recently I was looking into embedded programing of AVR microcontrollers.

At this site [URL] ....

I have encounter some code that implements delay

asm volatile ("nop");

From what I understand it is assembler code that creates delay - one processor clock long.

For C/C++ language it should be like ; or {} = null statement.

Now my question is how to implement this C/C++ code and prevent my compiler (WinAVR: AVR-GCC) to delete this command during optimization (-Os or -O2). Or is it simply better to use the assembler function.

I know I can use for-loop

volatile uint8_t foo
for(foo=0; foo<2; ++foo){}

but for that I have to create a variable = wasting 1 byte of RAM; correct?

View 11 Replies View Related

C/C++ :: Null Terminated String Function

Feb 12, 2015

how would I write a function that copies a null-terminated string from one char* buffer to another, without using strcpy? I am trying to avoid strcpy because of the null terminator.

Here is my attempt;

#include <algorithm>
#include <iostream>
static const size_t, data_size =32;
struct tString
{
char data[data_size];
};
std::string buffer = strArray1[0] + strArray2[0];
std::copy(buffer.begin(), buffer.end(), tString[0].data);

View 8 Replies View Related

C# :: Null Reference With Connection String

Nov 29, 2014

private DataSet1 GetData(string query) {
string conString = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;

The above is erring out with NullReferenceException

View 6 Replies View Related

C/C++ :: Why Is String Null Terminating Character Actually Needed

Dec 26, 2014

I know that the null at the end of the string indicates end of that string but why is it actually needed. Strings in C are just arrays of char variables. A "Hello" string would be stored in ascii code as:

char string[] = {72, 101, 108, 108, 111, 0}

When I have array of integers like

int intArray[] = {72, 101, 108, 108, 111}

I can perform various operations with it like comparision with other array etc. but I don't need terminating character

View 6 Replies View Related

C++ :: Compiler Not Recognizing Numbers

Sep 8, 2013

I'm working on this homework assignment where the program takes in the user's height in inches, weight in pounds, and age, then calculates their hat size, jacket size and waist size. The formulas for these are as follows:

Hat: (weight/height) x 2.9

Jacket: (height x weight)/288 then adjusted by adding 1/8 an inch for every 10 years over the age of 30 (The adjustment only takes place after a full 10 years, so there is no adjustment for 30-39, but there is for 40)

Waist: (weight/5.7) then adjusted by adding 1/10 of an inch for each 2 years over the age of 28 (the adjustment only takes place after a full 2 years, so no adjustment for 29, but there is for 30, etc)

I'm supposed to utilize functions for each of the three formulas.

There's a couple things I can't figure out.

1. Why won't the compiler recognize 2.9 and 5.7 as numbers?

2. How do I adjust the calculation for the jacket and waist based on age?

Here's what I've got so far:

#include <cstdlib>
#include <iostream>
using namespace std;
double hatSize(int weight, int height);
double jacketSize(int weight, int height, int age);
double waistSize(int weight, int height, int age);

[code]....

View 1 Replies View Related

C++ :: File I/O Not Recognizing Contents Correctly

Nov 17, 2014

I have a program that's not doing what I want it to do. This is the assignment:

The nth term of the sequence of triangle numbers is given by, tn = 1/2 n (n+1); so the first ten triangle numbers are:

1, 3, 6, 10, 15, 21, 28, 36, 45, 55,...

By converting each letter in a word to a number corresponding to its alphabetical position and adding these values we form a word value. For example, the word value for SKY is 19 + 11 + 25 = 55 = t10. If the word value is a triangle number then we shall call the word a triangle word.

the 'words.txt' has a bunch of words in this format:

"ABSTRACT"
"YOUTH"

there's about 1000 words in that format.

And for any triangle words I find, I put it into another text file which I called triangle.txt.

Now for my program, it pulls the 'words.txt' file just fine but it doesn't recognize any of the words in the file as triangle words.

#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
#include <cmath>
#include <cstdlib>
int getCharValue(char a);
double sum1(std::string name);

[code]....

View 2 Replies View Related

C++ :: Null Terminator Same As Null And Through False Value?

Feb 18, 2014

I am looking at one of the functions of an exercise:

void escape(char * s, char * t) {
int i, j;
i = j = 0;
while ( t[i] ) {
/* Translate the special character, if we have one */
switch( t[i] ) {

[code]...

Notice the while loop evaluates the current value in t to true or false. When we hit the null terminator, does that get evaluated as 0 and hence evaluates as a falsy value so the while loop exits?

View 1 Replies View Related

C :: Linked List Program Not Recognizing A Function

Oct 22, 2014

I'm writing a linked list program for class that has a simple text based menu and I believe I am nearly done, it just wont recognize my "count" function as a function and I don't know why. The error comes up at line 70.

Code:

#include <stdio.h>
#include <stdlib.h>
typedef struct node {
int datum;
struct node *next;
} node_t;

[code]....

View 3 Replies View Related

C++ :: Comparing Two String In If Statement

Aug 31, 2014

i actually i want store string in r and try to compare other string (room_no) in function check but i try many time it still having error

#include<iostream>
#include<conio.h>
#include<fstream>

[Code].....

View 2 Replies View Related

C# :: Session Is Null But Not Null?

Mar 31, 2015

When you login to my site my loginservice which is done by ajax and json make a session called context.Session["Name"]. With BreakPoints it shows that everything is good and the variables are in place. However when I use Session["Name"] it comes out as null.

I will add my code at the bottem not

using System;
using System.Collections.Generic;
using System.Linq;

[Code].....

View 2 Replies View Related

C++ :: Creating And Joining String Objects - Suffix Increment Operator In Cout Statement

Mar 7, 2013

Here is the code:

// Creating and joining string objects
#include <iostream>
#include <string>
using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::getline;
// List names and ages
void listnames(string names[], string ages[], size_t count) {

[Code] ....

I may be wrong, but the problem seems to be in the function "listnames". Specifically, the output statement inside the while loop. I don't understand , how the ++ operator is behaving in this statement. The output produced does not match what's printed in the book. I usually just type all the examples, but with this one I also downloaded the source code from the book's website to make sure the error wasn't due to mistyping.

View 4 Replies View Related

C++ :: Input With String Statement - Output Result With HTML Tags To Populate Web Page

May 3, 2013

I'm working on a CGI application. I'm trying to test my input with a switch statement and output the result with html tags to populate a web page. From within the switch, I've coded as follows:

HTML Code:
switch(mFunc) {
case 0:
cout << "<p><b>YOU ENTERED THE FOLLOWING TO BE CALCULATED:</b></p>" "<h2>"<< number1 <<"+" << number2 << "</h2>" << endl;
break;
case 1:
cout << "You've entered" << number1 <<"-" << number2 << "to be evaluated" << endl;
break;

I know that I'll need to put this in an html body with a content type as such:

HTML Code:
cout << "Content-type: text/html
";
cout << "<html><body>
";

Am I able to do that directly inside of the switch statement?

View 11 Replies View Related

C++ :: Transfer If-else Statement Into Switch Statement?

Sep 7, 2013

How to make if else code below into SWITCH STATEMENT?

cout << "Enter the temperature: ";
cin >> temp;
cout << "Enter the pressure: ";
cin >> pressure;
cout <<endl;

[Code]....

View 6 Replies View Related

C :: Getting Null Pointers In Most Of Functions

Oct 15, 2014

For some reason I keep getting null pointers in most of my functions, and in my convertTime function the numbers are way higher than they should be.

Code:

//Utils.H header file----------------------------------------------

//This function takes the radius of a circle and returns the diameter, the circumference and the area.
int circleStatistics(double radius, double *diameter, double *circumference, double *area);

//This function takes a number of days and returns how many years, weeks and remaining days that is.
int convertTime(int days, int *y, int *w, int *d);

//This function takes a length of time and calculates the dilation of that time at a percentage of the speed of light.
int lorentzTimeDilation(double normalTime, double percentC, double *dilatedTime);

[Code] ....

View 3 Replies View Related

C++ :: Pointing To NULL And 0 The Same Thing?

Apr 13, 2014

Is:

char *endp = NULL;

the same thing as:

char *endp = 0;

?

View 1 Replies View Related

C++ :: Using STRTOK With Null Fields?

Jul 23, 2013

I am beginner in C++ programming. And i was try use STRTOK code with NULL fields, but in ARRAY fields NULL values is skiped. For example:

input text in Memo2:

AnsiString PAT02[100][20];
for (int IndexVRadku02 = 0; IndexVRadku02 < Memo2->Lines->Count ; IndexVRadku02++) {
AnsiString PNF02 = Memo2->Lines->Strings[IndexVRadku02];
char * PN02;

[Code] ....

Result:

Array 00 01 02 03 04 05
00 0000 TEXT1 TEXT2
01 0002 TEXT3 TEXT4 TEXT5
02 0003 TEXT6

But i need this result:

Array 00 01 02 03 04 05
00 0000 TEXT1 TEXT2
01 0002 TEXT3 TEXT4 TEXT5
02 0003 TEXT6

View 2 Replies View Related

C++ :: Point Of NULL In CString

Jul 9, 2014

I dont see any point of NULL in cstring. The code given below just outputs same as it would have done with NULL. My understanding is if size of char array is less than length of char array then null must be manually added?

#include <iostream>
using namespace std;
int main(){
char chr[0];
cin>>chr;//or if you use cin.getline;
cout<<chr<<endl;
return 0;
}

Enter something: hellowwwww
hellowwwww
Segmentation fault (core dumped)

why? for NULL char or something else?

View 1 Replies View Related

C++ :: Pointer As Parameter Is Null?

Apr 9, 2014

In my raytracer-project I have the following function:

bool hitObjects(Ray &ray, std::vector<Object *> &objects, Vector3& normal, Material *mat) {
double tmin = K_HUGE_VALUE;
double t;

[Code]....

When I try to run this, I only get the message "Material pointer is null". So, somehow the pointer is null after the hitObjects-function is called, even though it isn't inside that function.

View 6 Replies View Related

C/C++ :: MySQL - Resultset Is Always Null

Jul 30, 2014

The resultset is always null and the connection is alive. The VS2013 debugger says that mysqlcppconn.dll has no debugging symbols. Tested the query on a mysql console and it worked fine, it returned 1.

CDatabase::CDatabase(CSettings* settings) {
settings = settings;
try {
Connection* con = get_driver_instance()->connect("", "", "");
con->setSchema("hyperbot");
cout << "Connected." << endl << endl;

[Code] .....

I also get these strange warnings on compile:

1>c:program files (x86)mysqlmysql connector c++ 1.1.3includecppconnsqlstring.h(38):
warning C4251: 'sql::SQLString::realStr' : class 'std::basic_string<char,std::char_traits<char>,std::allocator<char>>'
needs to have dll-interface to be used by clients of class 'sql::SQLString'

[Code] ......

View 10 Replies View Related

C/C++ :: Strtok And Null Checking?

Mar 1, 2015

I'm playing around with parts of code and am coming across some errors. Most of my concern is related to strtok(). I've used it before but with a char* named token. I used a while loop to continuously check whether token was equal to NULL. In the following code, however, there aren't any checks. I was wondering if that is why this code prints (null) while running. Also, I would like to know if it is possible to read input like this code attempts to do - assigning tokens to each variable one after the other.

The format of the input:

Zucchini, Squash, pound
Yellow, Squash, pound
Tomatoes, Ugly Ripe, each
#include <stdio.h>
#include <stdlib.h>

[code]....

View 3 Replies View Related

C/C++ :: Initializing Pointer To NULL?

May 17, 2014

So I'm writing a small program for class, and for some reason I keep getting an error when trying to initialize head to NULL. Even threw in the namespace just to see, nothin'.

#ifndef NUMBERLIST_H
#define NUMBERLIST_H
using namespace std;

[Code].....

There's my header file. Not sure what I'm doing wrong with the constructor.

EDIT: Got it to work with nullptr, but still curious why that isn't working

View 2 Replies View Related

C# :: Linq To SQL With Null Value In WHERE Clause

Apr 13, 2015

I am trying to query fields in a where clause using LINQ to SQL and for some reason I cannot figure out why it doesn't work:

var qryGetMonsterID = (from students in dbContext.tblStudentPersonals
where (students.givenname.Equals(fn)) && (students.familyname.Equals(ln)) && (students.middlename.Equals(mn)) && (students.email.Equals(e))
select students);

The returned SQL Syntax is:

SELECT [t0].[monsterid], [t0].[givenname], [t0].[middlename], [t0].[familyname], [t0].[homeaddress], [t0].[city], [t0].[state], [t0].[postal], [t0].[primaryphone], [t0].[secondaryphone], [t0].[email], [t0].[username], [t0].[lastmodified], [t0].[modifiedby]
FROM [dbo].[tblStudentPersonal] AS [t0]
WHERE ([t0].[givenname] = @p0) AND ([t0].[familyname] = @p1) AND ([t0].[middlename] = @p2) AND ([t0].[email] = @p3)

Not sure but the values for middle name could be null - because not everyone has a middle name and the same is true for e-mail.

View 6 Replies View Related

C# :: Need To Replace Null Value By 0 To Calculate

Jun 28, 2014

I have a datagridview (dgv) that is bound to database:

QtyOnHand QtyOnHold QtySold QtyAvailable
10 2 1 null
12 null null null
null null null null
7 5 null null
25 null 5 null

I want to iterate through the datagridview and calculate the last column with this formula:

QtyAvailable = QtyOnHand - QtyOnHold - QtySold

so the datagridview should become:

QtyOnHand QtyOnHold QtySold QtyAvailable
10 2 1 7
12 null null 12
null null null null
7 5 null 2
25 null 5 20

I use this code:

foreach (DataGridViewRow row in dgv.Rows){
if (string.IsNullOrEmpty(row.Cells["QtyOnHand"].Value.ToString())){
row.Cells["QtyAvailable"].Value =
Convert.ToInt32(row.Cells["QtyOnHand"].Value) -
Convert.ToInt32(row.Cells["QtyOnHold"].Value) -
Convert.ToInt32(row.Cells["QtySold"].Value) -
Convert.ToInt32(row.Cells["QtyAvailable"].Value);
}
}

The problem is when any of the value on the right side of the equation is null, the whole equation is invalid. I need to replace the null values by 0 on the fly so that it can be calculated. Note that I do not want to actually replace the null values in the second and third columns of the table, just replace it in the equation whenever it applies to make the calculation work.

View 4 Replies View Related

C++ :: Create Null Pointer After Using Delete

Aug 7, 2014

In jumping into C++ it says something like this: It's not necessary but when you delete a pointer it's a good idea to reset it as a null pointer. That if your code try's to dereference the pointer after being freed, your program will crash. This happens to a lot of experienced programmers.

This could corrupt users data. delete p_int;
p_int = NULL;

1. If you can deference a pointer after the memory is freed, why can't you just delete the pointer?

2. If you can do 1, how do you delete the pointer using code?

3. Every thing I've read says that free memory is handed out in a sequenced order. I don't believe that is true at all. I may be wrong. Why can't you put the data in any number of places if it will fit. Isn't the compiler smart enough to know where bytes (bits)and pieces are stored?

4. If you storing anything in free memory must use a pointer to it?

5. Can a pointer or something similar be used with stack memory?

View 13 Replies View Related







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