[Solved] Splitting a string into integers

Since you are sure the string will contain digits, subtract each character from ‘0’ to get their numeric value. int sum = 0; fgets(str, sizeof str, stdin); char *s = &str; while(*s != ‘\0’) { sum += *(s++) – ‘0’; } printf(“the sum of the digits is: %d”, sum); solved Splitting a string into integers

[Solved] Check string format consist of specific words then number then specific words in c# [closed]

It’s really easy to make a regular expression to get matches: string[] input = new string[6] { “[email protected]”, // match “[email protected]”, // match “[email protected]”, // match “[email protected]”, // not a match “[email protected]”, // not a match “[email protected]” // not a match }; string pattern = @”Auto_gen_\d{4}@mail.com”; //\d{4} means 4 digits foreach (string s in input) … Read more

[Solved] Split list in to sublist in C# [duplicate]

You can use this code. here I’m using string for demo, you can use your guid. var list = new List<string> { “a”, “b”, “c”, “d”, “e” }; var threashold = 2; var total = list.Count(); var taken = 0; var sublists = new List<List<string>>(); //your final result while (taken < total) { var sublst … Read more

[Solved] c# foreach loop formatting

Hmmm, I haven’t tested it. I hope it helps you. I would do it using two foreach inside the main while SearchResultSet results = session.Search(searchRequest); results.GetCount()); IEnumerable columns = results.GetColumns(); bool printColumns = true; while (results.HasNext()) { if(printColumns){ foreach (string column in columns) { Console.WriteLine(String.Format(“{0}|”, column)); //Will print Unique_ID|Address|etc… } } printColumns = false; foreach … Read more

[Solved] class that gets a value from database [closed]

public static class myMethods { public static string getName(){ string name = “”; ConnectionStringSettings myConnectionString = ConfigurationManager.ConnectionStrings[“LibrarySystem.Properties.Settings.LibraryConnectionString”]; using (SqlConnection myDatabaseConnection = new SqlConnection(myConnectionString.ConnectionString)) { myDatabaseConnection.Open(); using (SqlCommand mySqlCommand = new SqlCommand(“select Top 1 * from Setting Order By SettingID Desc”, myDatabaseConnection)) using (SqlDataReader sqlreader = mySqlCommand.ExecuteReader()) { if (sqlreader.Read()) { name = sqlreader[“Name”].ToString(); } } … Read more

[Solved] C# DateTime not working for MSSQL stored procedure [closed]

Lets work backwards here – your stored proc will never work, you have not specified a field for the where, and it has 2 missing close parentheses. select * from MyTable where between CAST(@startDate AS VARCHAR(100) and CAST(@EndDateAS VARCHAR(100) should be select * from MyTable where SOMEFIELD between CAST(@startDate AS VARCHAR(100)) and CAST(@EndDateAS VARCHAR(100)) In … Read more

[Solved] Operator >= returns false when it actually true

You haven’t provided example values of p.y and sign_y, so it’s difficult to tell for sure. But the problem is almost certainly that p.y * sign_y is not exactly equal to 180; however it will be rounded when you print it. I suspect that if your print the value of (p.y * sign_y) – end_pos.y, … Read more

[Solved] Finding solutions for a given pair (number of factors, number of prime factors)

Let p1, p2, p3, … pk be the prime factors of some positive integer n. By the fundamental theorem of arithmetic, n can be represented as p1e1•p2e2•p3e3• … pkek for some positive integers e1, e2, e3, … ek. Furthermore, any such set of such positive integers represents one positive integer in this way. Every factor … Read more

[Solved] C Programming Guessing Game

Here’s an idea for you to do this in your code: char answer=”y”; do { // … printf( “Want to play again (y/n)? ” ); scanf( ” %c”, &answer ); // Mind ^ the space here to discard any // previously read newline character } while ( answer == ‘y’ ); 3 solved C Programming … Read more