Questions tagged [c]

1101678 questions
1.3k

votes
25

answer
2.3m

Views

Easiest way to convert int to string in C++

What is the easiest way to convert from int to equivalent string in C++. I am aware of two methods. Is there any easier way? (1) int a = 10; char *intStr = itoa(a); string str = string(intStr); (2) int a = 10; stringstream ss; ss
Nemo
4.2k

votes
1

answer
2.1m

Views

The Definitive C++ Book Guide and List

This question attempts to collect the few pearls among the dozens of bad C++ books that are published every year. Unlike many other programming languages, which are often picked up on the go from tutorials found on the Internet, few are able to quickly pick up C++ without studying a well-written C++...
2.8k

votes
30

answer
2.1m

Views

How do I iterate over the words of a string?

I'm trying to iterate over the words of a string. The string can be assumed to be composed of words separated by whitespace. Note that I'm not interested in C string functions or that kind of character manipulation/access. Also, please give precedence to elegance over efficiency in your answer. The...
1.5k

votes
28

answer
1.8m

Views

How do I generate a random int number in C#?

How do I generate a random integer in C#?
Rella
832

votes
19

answer
1.6m

Views

How to initialize all members of an array to the same value?

I have a large array in C (not C++ if that makes a difference). I want to initialize all members to the same value. I could swear I once knew a simple way to do this. I could use memset() in my case, but isn't there a way to do this that is built right into the C syntax?
Matt
94

votes
10

answer
1.6m

Views

Regular expression to check if password is “8 characters including 1 uppercase letter, 1 special character, alphanumeric characters”

I want a regular expression to check that a password must be eight characters including one uppercase letter, one special character and alphanumeric characters. And here is my validation expression which is for eight characters including one uppercase letter, one lowercase letter, and one number or...
Rania Umair
1.5k

votes
26

answer
1.5m

Views

How to print without newline or space?

The question is in the title. I'd like to do it in python. What I'd like to do in this example in c: #include int main() { int i; for (i=0; i>> for i in xrange(0,10): print '.' . . . . . . . . . . >>> for i in xrange(0,10): print '.', . . . . . . . . . . In Python print will add a \n or a space, h...
Andrea Ambu
767

votes
20

answer
1.5m

Views

How do I determine the size of my array in C?

How do I determine the size of my array in C? That is, the number of elements the array can hold?
Mark Harrison
476

votes
24

answer
1.4m

Views

How to generate a random int in C?

Is there a function to generate a random int number in C? Or will I have to use a third party library?
Kredns
22.3k

votes
22

answer
1.3m

Views

Why is it faster to process a sorted array than an unsorted array?

Here is a piece of C++ code that seems very peculiar. For some strange reason, sorting the data miraculously makes the code almost six times faster. #include #include #include int main() { // Generate data const unsigned arraySize = 32768; int data[arraySize]; for (unsigned c = 0; c < arraySize;...
GManNickG
282

votes
11

answer
1.3m

Views

Convert char to int in C and C++

How do I convert a char to an int in C and C++?
mainajaved
2.1k

votes
25

answer
1.2m

Views

What is the best way to iterate over a dictionary?

I've seen a few different ways to iterate over a dictionary in C#. Is there a standard way?
Jake Stewart
404

votes
17

answer
1.2m

Views

Adding values to a C# array

Probably a really simple one this - I'm starting out with C# and need to add values to an array, for example: int[] terms; for(int runs = 0; runs < 400; runs++) { terms[] = runs; } For those who have used PHP, here's what I'm trying to do in C#: $arr = array(); for ($i = 0; $i < 10; $i++) { $arr[] =...
Ross
1.5k

votes
25

answer
1.2m

Views

Get int value from enum in C#

I have a class called Questions (plural). In this class there is an enum called Question (singular) which looks like this. public enum Question { Role = 2, ProjectFunding = 3, TotalEmployee = 4, NumberOfServers = 5, TopBusinessConcern = 6 } In the Questions class, I have a get(int foo) function that...
jim
645

votes
24

answer
1.2m

Views

What does the C++ standard state the size of int, long type to be?

I'm looking for detailed information regarding the size of basic C++ types. I know that it depends on the architecture (16 bits, 32 bits, 64 bits) and the compiler. But are there any standards for C++? I'm using Visual Studio 2008 on a 32-bit architecture. Here is what I get: char : 1 byte short :...
Jérôme
1.9k

votes
30

answer
1.1m

Views

What is a NullReferenceException, and how do I fix it?

I have some code and when it executes, it throws a NullReferenceException, saying: Object reference not set to an instance of an object. What does this mean, and what can I do to fix this error?
520

votes
14

answer
1.1m

Views

C# DateTime to “YYYYMMDDHHMMSS” format

I want to convert a C# DateTime to 'YYYYMMDDHHMMSS' format. But I don't find a built in method to get this format? Any comments?
SARAVAN
2k

votes
30

answer
1.1m

Views

How do I get a consistent byte representation of strings in C# without manually specifying an encoding?

How do I convert a string to a byte[] in .NET (C#) without manually specifying a specific encoding? I'm going to encrypt the string. I can encrypt it without converting, but I'd still like to know why encoding comes to play here. Also, why should encoding be taken into consideration? Can't I simply...
Agnel Kurian
833

votes
10

answer
1.1m

Views

How to make HTTP POST web request

How can I make an HTTP request and send some data using the POST method? I can do GET request but have no idea how to make a POST.
Hooch
473

votes
28

answer
1.1m

Views

How can I convert String to Int?

I have a TextBoxD1.Text and I want to convert it to an int to store it in a database. How can I do this?
turki2009
574

votes
13

answer
1.1m

Views

Using boolean values in C

C doesn't have any built-in boolean types. What's the best way to use them in C?
neuromancer
395

votes
11

answer
1.1m

Views

Convert int to string?

How can I convert an int datatype into a string datatype in C#?
The Worst Shady
2.7k

votes
22

answer
1.1m

Views

Cast int to enum in C#

How can an int be cast to an enum in C#?
lomaxx
418

votes
22

answer
1.1m

Views

How do I find the length of an array?

Is there a way to find how many values an array has? Detecting whether or not I've reached the end of an array would also work.
Maxpm
747

votes
14

answer
1.1m

Views

How do I turn a C# object into a JSON string in .NET?

I have classes like these: class MyDate { int year, month, day; } class Lad { string firstName; string lastName; MyDate dateOfBirth; } And I would like to turn a Lad object into a JSON string like this: { 'firstName':'Markoff', 'lastName':'Chaney', 'dateOfBirth': { 'year':'1901', 'month':'4', 'day':...
Hui
351

votes
12

answer
1.1m

Views

How can I convert a std::string to int?

Just have a quick question. I've looked around the internet quite a bit and I've found a few solutions but none of them have worked yet. Looking at converting a string to an int and I don't mean ASCII codes. For a quick run-down, we are passed in an equation as a string. We are to break it down, fo...
Brandon
462

votes
12

answer
1m

Views

Converting a String to DateTime

How do you convert a string such as 2009-05-08 14:40:52,531 into a DateTime?
1.3k

votes
30

answer
1m

Views

How do I remedy the “The breakpoint will not currently be hit. No symbols have been loaded for this document.” warning?

C# desktop application on express edition. Worked then didn't work 5 seconds later. I tried the following. Ensure debug configuration, debug flag, and full debug info are set on all assemblies. Delete all bin and obj folders and all DLLs related to the project from my entire machine. Recreate projec...
496

votes
7

answer
1m

Views

Read file line by line using ifstream in C++

The contents of file.txt are: 5 3 6 4 7 1 10 5 11 6 12 3 12 4 Where 5 3 is a coordinate pair. How do I process this data line by line in C++? I am able to get the first line, but how do I get the next line of the file? ifstream myfile; myfile.open ('text.txt');
dukevin
864

votes
7

answer
1m

Views

Group by in LINQ

Let's suppose if we have a class like class Person { internal int PersonID; internal string car ; } Now I have a list of this class: List persons; Now this list can have multiple instances with same PersonIDs, for example: persons[0] = new Person { PersonID = 1, car = 'Ferrari' }; persons[1] =...
test123
963

votes
19

answer
1m

Views

How to Sort a List<T> by a property in the object

I have a class called Order which has properties such as OrderId, OrderDate, Quantity, and Total. I have a list of this Order class: List objListOrder = new List(); GetOrderList(objListOrder); // fill list of orders Now I want to sort the list based on one property of the Order object, for example I...
Shyju
491

votes
14

answer
1m

Views

Sleep for milliseconds

I know the POSIX sleep(x) function makes the program sleep for x seconds. Is there a function to make the program sleep for x milliseconds in C++?
Prasanth Madhavan
2.2k

votes
26

answer
992.8k

Views
557

votes
5

answer
973.4k

Views

How convert byte array to string [duplicate]

This question already has an answer here: How to convert UTF-8 byte[] to string? 13 answers I created a byte array with two strings. How do I convert a byte array to strings? var binWriter = new BinaryWriter(new MemoryStream()); binWriter.Write('value1'); binWriter.Write('value2'); binWriter.Seek(0...
Oksana
1.6k

votes
30

answer
948.2k

Views

How to create Excel (.XLS and .XLSX) file in C# without installing Ms Office?

How can I create an Excel Spreadsheet with C# without requiring Excel to be installed on the machine that's running the code?
1.6k

votes
30

answer
944.9k

Views

Create Excel (.XLS and .XLSX) file from C#

How can I create an Excel Spreadsheet with C# without requiring Excel to be installed on the machine that's running the code?
583

votes
9

answer
928.5k

Views

How to get the URL of the current page in C# [duplicate]

This question already has an answer here: Get URL of ASP.Net Page in code-behind [duplicate] 10 answers Can anyone help out me in getting the URL of the current working page of ASP.NET in C#?
872

votes
15

answer
923.7k

Views

Calculate difference between two dates (number of days)?

I see that this question has been answered for Java, JavaScript, and PHP, but not C#. So, how might one calculate the number of days between two dates in C#?
leora
786

votes
13

answer
922.1k

Views

How to convert UTF-8 byte[] to string?

I have a byte[] array that is loaded from a file that I happen to known contains UTF-8. In some debugging code, I need to convert it to a string. Is there a one liner that will do this? Under the covers it should be just an allocation and a memcopy, so even if it is not implemented, it should be po...
BCS
5.6k

votes
30

answer
919.3k

Views

What is the difference between String and string in C#?

Example (note the case): string s = 'Hello world!'; String s = 'Hello world!'; What are the guidelines for the use of each? And what are the differences?