int main(void)
{
const int FREEZING = 0;
float temperature;
int cold_days = 0;
int all_days = 0;
printf("Enter the list of daily lowe temperatures.\n");
printf("Use Celsius, and enter q to quit.\n");
while (scanf("%f", &temperature)==1)
{
all_days++;
if (temperature < FREEZING)
{
cold_days++;
}
}
if (all_days != 0)
{
printf("%d days total: %.1f%% were below freezing.\n", all_days, 100.0 * (float) cold_days / all_days);
}
if (all_days ==0)
{
printf("No data entered!\n");
}
return 0;
}
#include
#define SPACE ' '
int main(void)
{
char ch;
ch=getchar();
while (ch != '\n')
{
if (ch==SPACE)
{
putchar(ch);
} else {
putchar(ch + 1);
}
ch = getchar(); //get next character
}
putchar(ch);
return(0);
}
Imports System
Imports System.IO
Namespace Apress.VisualBasicRecipes.Chapter05
Public Class Recipe05_03 'expanded by me somewhat using http://msdn.microsoft.com/en-us/library/dd997370.aspx
Public Shared Sub Main()
Dim dirPath As String = "C:\inetpub\wwwroot\"
Dim dirs = From folder In Directory.EnumerateDirectories(dirPath)
Dim folderArray(20, 1) As String
Dim i As Integer = 0
For Each folder In dirs
folderArray(i, 0) = folder.Substring(folder.LastIndexOf("\") + 1)
folderArray(i, 1) = folder
Console.WriteLine("[{0}] {1}", i, folderArray(i, 0))
i = i + 1
Next
Console.WriteLine("select a directory to copy")
Dim sourceDirNum = Console.ReadLine()
Dim sourceDirName = folderArray(sourceDirNum, 0)
Dim sourceDirPath = folderArray(sourceDirNum, 1)
displayNamePath(sourceDirName, sourceDirPath)
Console.WriteLine("Please enter the name of the new directory to create")
Dim destDirName = Console.ReadLine()
Dim destDirPath = sourceDirPath.Substring(0, sourceDirPath.LastIndexOf(sourceDirName)) + destDirName
displayDestPath(destDirName, destDirPath)
CopyDirectory(sourceDirPath, destDirPath)
End Sub
Shared Sub displayNamePath(ByVal arg1, ByVal arg2)
Console.WriteLine("-> You will copy the {0} directory", arg1)
Console.WriteLine("-> located at {0}", arg2)
End Sub
Shared Sub displayDestPath(ByVal arg1, ByVal arg2)
Console.WriteLine("-> You will create a directory named {0} ", arg1)
Console.WriteLine("-> located at {0}", arg2)
End Sub
Shared Sub CopyDirectory(ByVal sourceDirPath, ByVal destDirPath)
Dim source As New DirectoryInfo(sourceDirPath)
Dim destination As New DirectoryInfo(destDirPath)
If Not destination.Exists Then
Console.WriteLine("Creating the destination folder {0}", destination.FullName)
destination.Create()
End If
'Copy all files
Dim files As FileInfo() = source.GetFiles
For Each File As FileInfo In files
Console.WriteLine("Copying the {0} file...", File.Name)
File.CopyTo(Path.Combine(destination.FullName, File.Name))
Next
'Process subdirectories
Dim dirs As DirectoryInfo() = source.GetDirectories
'unfortunately could not figure out how to copy subs.
End Sub
End Class
End Namespace
Imports System
Imports System.IO
Public Class Test
Public Shared Sub Main()
'specifiy the directories you want to manipulate
Dim di As DirectoryInfo = New DirectoryInfo("C:\new\MyDir")
Try
'determine whether the directory exists
If di.Exists Then
Console.WriteLine("That directory exists already")
Return
End If
'try to create that directory
di.Create()
Console.WriteLine("the directory was created successfully")
'delete the directory
di.Delete()
Console.WriteLine("The directory was deleted successfully")
Catch ex As Exception
Console.WriteLine("The process failed: {0}", ex.ToString())
End Try
End Sub
End Class
No comments:
Post a Comment