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.
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;
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
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?
PROGRAM:- #include<fstream.h> //for reading and writing files #include<conio.h> //for clrscr() #include<string.h> //for string characters #include<stdio.h> //for gets and puts function #include<process.h> //for exit function #include<iomanip.h> //for setw function #include<dos.h> //for delay and sleep function
My programs complies and runs. However, whenever i try to enter something when prompt to enter the number of accounts i wanted to create my program crashes.
By the way, im using codeblocks.
it says
terminated called after throwing an instance of 'std:: out of range'. what(): basic_string::substr"
Code: #include <iostream> #include "clsInterest.h" #include "clsDate.h" using namespace std;
I am currently developing a sync module using asp.net. I am getting data from an external database (mysql database) The problem is I am getting the error "Connection unexpectedly terminated" when filling the dataset.
Here's my code
string P_contact = "SELECT A.id, B.firstname, B.middlename, B.lastname FROM Accounts A, Contacts B WHERE A.id = B.id"; MySqlDataAdapter db_P_contact = new MySqlDataAdapter(P_contact, conn); DataSet ds3 = new DataSet(); DataTable dt3 = new DataTable();
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;
//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);
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)
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.
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.
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'
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.
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
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.
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.
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?
my program is printing out a random symbol afterwards , when trying to copy a sequence of chars into a new buffer.
Code:
#include <stdio.h>#include <stdlib.h> int tokenCopy(char* dest, const char* src, int destSize); int main() { char buff[3]; int n = tokenCopy(buff, "This is a string", 3); printf("%d '%s' ", n, buff);