xxxxxxxxxx
int arg1 = atoi(argv[1]); //argv[0] is the program name
//atoi = ascii to int
xxxxxxxxxx
strcpy(str, "98993489");
val = atoi(str);
printf("String value = %s, Int value = %d\n", str, val);
xxxxxxxxxx
#include <stdio.h>
#include <stdlib.h>
int main() {
char c = '7';
int i = atoi(&c);
printf("Character '%c' as an integer: %d\n", c, i);
return 0;
}
xxxxxxxxxx
char a = 'a';
int ia = (int)a;
/* note that the int cast is not necessary -- int ia = a would suffice */
char a = '4';
int ia = a - '0';
/* check here if ia is bounded by 0 and 9 */
xxxxxxxxxx
using System;
namespace Dates
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter date");
string dateInput = Console.ReadLine();
Console.WriteLine("Enter time");
string timeInput = Console.ReadLine();
Console.WriteLine("Enter number of hours to add");
string hoursInput = Console.ReadLine();
int hours = int.Parse(hoursInput);
string[] timeParts = timeInput.Split(":");
string[] dateParts = dateInput.Split("-");
DateTime date = new DateTime(
int.Parse(dateParts[0]),
int.Parse(dateParts[1]),
int.Parse(dateParts[2]),
int.Parse(timeParts[0]),
int.Parse(timeParts[1]),
0
);
date = date.AddHours(hours);
Console.WriteLine(date.ToString("yyyy-MM-dd HH:mm"));
}
}
}